fix(snmp): resolve TypeScript type errors for Deno strict mode
- Add Buffer import from node:buffer to manager.ts and types.ts - Fix error handling type assertions (error/retryError/stdError as unknown) - Add explicit type annotation to byte parameter in isPrintableAscii check - All tests now passing (3 SNMP tests + 10 logger tests)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import * as snmp from "npm:net-snmp@3.20.0";
|
import * as snmp from "npm:net-snmp@3.20.0";
|
||||||
|
import { Buffer } from "node:buffer";
|
||||||
import type { IOidSet, ISnmpConfig, TUpsModel, IUpsStatus } from './types.ts';
|
import type { IOidSet, ISnmpConfig, TUpsModel, IUpsStatus } from './types.ts';
|
||||||
import { UpsOidSets } from './oid-sets.ts';
|
import { UpsOidSets } from './oid-sets.ts';
|
||||||
|
|
||||||
@@ -245,7 +246,7 @@ export class NupstSnmp {
|
|||||||
// Handle specific types that might need conversion
|
// Handle specific types that might need conversion
|
||||||
if (Buffer.isBuffer(value)) {
|
if (Buffer.isBuffer(value)) {
|
||||||
// If value is a Buffer, try to convert it to a string if it's printable ASCII
|
// If value is a Buffer, try to convert it to a string if it's printable ASCII
|
||||||
const isPrintableAscii = value.every(byte => byte >= 32 && byte <= 126);
|
const isPrintableAscii = value.every((byte: number) => byte >= 32 && byte <= 126);
|
||||||
if (isPrintableAscii) {
|
if (isPrintableAscii) {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
}
|
}
|
||||||
@@ -335,10 +336,10 @@ export class NupstSnmp {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.error('---------------------------------------');
|
console.error('---------------------------------------');
|
||||||
console.error('Error getting UPS status:', error.message);
|
console.error('Error getting UPS status:', error instanceof Error ? error.message : String(error));
|
||||||
console.error('---------------------------------------');
|
console.error('---------------------------------------');
|
||||||
}
|
}
|
||||||
throw new Error(`Failed to get UPS status: ${error.message}`);
|
throw new Error(`Failed to get UPS status: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,7 +374,7 @@ export class NupstSnmp {
|
|||||||
return value;
|
return value;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.error(`Error getting ${description}:`, error.message);
|
console.error(`Error getting ${description}:`, error instanceof Error ? error.message : String(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're using SNMPv3, try with different security levels
|
// If we're using SNMPv3, try with different security levels
|
||||||
@@ -424,11 +425,11 @@ export class NupstSnmp {
|
|||||||
return value;
|
return value;
|
||||||
} catch (retryError) {
|
} catch (retryError) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.error(`Retry failed for ${description}:`, retryError.message);
|
console.error(`Retry failed for ${description}:`, retryError instanceof Error ? retryError.message : String(retryError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with noAuthNoPriv as a last resort
|
// Try with noAuthNoPriv as a last resort
|
||||||
if (config.securityLevel === 'authPriv' || config.securityLevel === 'authNoPriv') {
|
if (config.securityLevel === 'authPriv' || config.securityLevel === 'authNoPriv') {
|
||||||
const retryConfig = { ...config, securityLevel: 'noAuthNoPriv' as 'noAuthNoPriv' };
|
const retryConfig = { ...config, securityLevel: 'noAuthNoPriv' as 'noAuthNoPriv' };
|
||||||
@@ -443,11 +444,11 @@ export class NupstSnmp {
|
|||||||
return value;
|
return value;
|
||||||
} catch (retryError) {
|
} catch (retryError) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.error(`Retry failed for ${description}:`, retryError.message);
|
console.error(`Retry failed for ${description}:`, retryError instanceof Error ? retryError.message : String(retryError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +479,7 @@ export class NupstSnmp {
|
|||||||
return standardValue;
|
return standardValue;
|
||||||
} catch (stdError) {
|
} catch (stdError) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.error(`Standard OID retry failed for ${description}:`, stdError.message);
|
console.error(`Standard OID retry failed for ${description}:`, stdError instanceof Error ? stdError.message : String(stdError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
* Type definitions for SNMP module
|
* Type definitions for SNMP module
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { Buffer } from "node:buffer";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UPS status interface
|
* UPS status interface
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user