remove Write-Warning for CAPIErrors.

Allow them to bubble up.
(Might be worth adding a helper function to print stacktrace?)
This commit is contained in:
onyx-and-iris 2023-08-16 16:36:43 +01:00
parent 844eaeabaa
commit 9b3d9f2250
4 changed files with 74 additions and 167 deletions

View File

@ -137,7 +137,6 @@ Function Get-RemotePotato {
Function Connect-Voicemeeter {
param([String]$Kind)
try {
switch ($Kind) {
"basic" {
return Get-RemoteBasic
@ -148,17 +147,8 @@ Function Connect-Voicemeeter {
"potato" {
return Get-RemotePotato
}
default { throw [LoginError]::new("Unknown Voicemeeter kind `"$Kind`"") }
}
}
catch [LoginError], [CAPIError] {
Write-Warning $_.Exception.ErrorMessage()
throw
}
catch [VMRemoteError] {
$_.Exception.ErrorMessage() | Write-Warning
if ($_.Exception.ErrorMessage() -eq "Couldn't get Voicemeeter path") {
Exit -1
default {
throw [LoginError]::new("Unknown Voicemeeter kind `"$Kind`"")
}
}
}

View File

@ -5,23 +5,17 @@ function Login {
param(
[string]$kindId
)
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_Login()
if ($retval -notin @(0, 1, -2)) {
throw [CAPIError]::new($retval, "VBVMR_Login")
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
switch ($retval) {
1 {
RunVoicemeeter -kindId $kindId
}
-2 {
throw [LoginError]::new("Login may only be called once per session. Fatal error... exiting.")
throw [LoginError]::new("Login may only be called once per session.")
}
}
@ -31,16 +25,10 @@ function Login {
function Logout {
Start-Sleep -m 20
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_Logout()
if ($retval -notin @(0)) {
throw [CAPIError]::new($retval, "VBVMR_Logout")
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
if ($retval -eq 0) { "Sucessfully logged out" | Write-Verbose }
}
@ -54,60 +42,36 @@ function RunVoicemeeter {
"potato" = $(if ([Environment]::Is64BitOperatingSystem) { 6 } else { 3 })
}
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([int64]$kinds[$kindId])
if ($retval -notin @(0)) {
throw [CAPIError]::new($retval, "VBVMR_RunVoicemeeter")
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
"Voicemeeter Engine running but GUI not launched. Launching GUI now." | Write-Verbose
Start-Sleep -s 1
}
function P_Dirty {
try {
$retval = [Voicemeeter.Remote]::VBVMR_IsParametersDirty()
if ($retval -notin @(0, 1)) {
throw [CAPIError]::new($retval, "VBVMR_RunVoicemeeter")
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
[bool]$retval
}
function M_Dirty {
try {
$retval = [Voicemeeter.Remote]::VBVMR_MacroButton_IsDirty()
if ($retval -notin @(0, 1)) {
throw [CAPIError]::new($retval, "VBVMR_RunVoicemeeter")
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
[bool]$retval
}
function VmType {
New-Variable -Name ptr -Value 0
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_GetVoicemeeterType([ref]$ptr)
if ($retval -notin @(0)) {
throw [CAPIError]::new($retval, "VBVMR_GetVoicemeeterType")
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
switch ($ptr) {
1 { return "basic" }
2 { return "banana" }
@ -117,16 +81,10 @@ function VmType {
function VmVersion {
New-Variable -Name ptr -Value 0
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_GetVoicemeeterVersion([ref]$ptr)
if ($retval -notin @(0)) {
throw [CAPIError]::new($retval, "VBVMR_GetVoicemeeterVersion")
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
$v1 = ($ptr -band 0xFF000000) -shr 24
$v2 = ($ptr -band 0x00FF0000) -shr 16
$v3 = ($ptr -band 0x0000FF00) -shr 8
@ -142,7 +100,6 @@ function Param_Get {
Start-Sleep -m 20
while (P_Dirty) { Start-Sleep -m 1 }
try {
if ($IS_STRING) {
$BYTES = [System.Byte[]]::new(512)
$retval = [int][Voicemeeter.Remote]::VBVMR_GetParameterStringA($PARAM, $BYTES)
@ -159,18 +116,12 @@ function Param_Get {
}
[single]$ptr
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
}
function Param_Set {
param(
[string]$PARAM, [Object]$VALUE
)
try {
if ($VALUE -is [string]) {
$retval = [int][Voicemeeter.Remote]::VBVMR_SetParameterStringA($PARAM, $VALUE)
if ($retval -notin @(0)) {
@ -183,27 +134,16 @@ function Param_Set {
throw [CAPIError]::new($retval, "VBVMR_SetParameterFloat")
}
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
}
function MB_Set {
param(
[int64]$ID, [single]$SET, [int64]$MODE
)
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_MacroButton_SetStatus($ID, $SET, $MODE)
if ($retval -notin @(0)) {
throw [CAPIError]::new($retval, "VBVMR_MacroButton_SetStatus")
}
}
catch [CAPIError] {
$_.Exception.ToString() | Write-Warning
throw
}
}
function MB_Get {
@ -214,16 +154,10 @@ function MB_Get {
while (M_Dirty) { Start-Sleep -m 1 }
New-Variable -Name ptr -Value 0.0
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_MacroButton_GetStatus($ID, [ref]$ptr, $MODE)
if ($retval -notin @(0)) {
throw [CAPIError]::new($retval, $MyInvocation.MyCommand)
}
}
catch [CAPIError] {
Write-Warning $_.Exception.ToString()
throw
}
[int]$ptr
}
@ -254,16 +188,10 @@ function Set_By_Script {
param(
[string]$script
)
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_SetParameters($script)
if ($retval -notin @(0)) {
throw [CAPIError]::new($retval, "VBVMR_SetParameters")
}
}
catch [CAPIError] {
Write-Warning $_.Exception.ToString()
throw
}
}
function Get_Level {
@ -271,15 +199,9 @@ function Get_Level {
[int64]$MODE, [int64]$INDEX
)
New-Variable -Name ptr -Value 0.0
try {
$retval = [int][Voicemeeter.Remote]::VBVMR_GetLevel($MODE, $INDEX, [ref]$ptr)
if ($retval -notin @(0)) {
throw [CAPIError]::new($retval, "VBVMR_GetLevel")
}
}
catch [CAPIError] {
Write-Warning $_.Exception.ToString()
throw
}
[float]$ptr
}

View File

@ -8,6 +8,6 @@ function Get_VMPath {
return $(Get-ItemPropertyValue -Path ($REG_KEY + $VM_KEY) -Name UninstallString | Split-Path -Parent)
}
catch {
throw [VMRemoteError]::new("Couldn't get Voicemeeter path")
throw [VMRemoteError]::new("Unable to fetch Voicemeeter path from the Registry.")
}
}

View File

@ -24,14 +24,9 @@ function Set_Profile {
param(
[Object]$DATA, [string]$CONF
)
try {
if ($null -eq $DATA -or -not $DATA.$CONF) {
throw [VMRemoteErrors]::new("No profile named $CONF was loaded")
throw [VMRemoteErrors]::new("No profile named '$CONF' has been loaded into memory.")
}
Param_Set_Multi -HASH $DATA.$CONF
Start-Sleep -m 1
}
catch [VMRemoteErrors] {
Write-Warning $_.Exception.ErrorMessage()
}
}