refactor(enclave): enhance error extraction and logging for better debugging
This commit is contained in:
@@ -17,12 +17,19 @@ function extractErrorMessage(err: unknown): string {
|
||||
if (typeof obj.message === 'string') return obj.message;
|
||||
if (typeof obj.error === 'string') return obj.error;
|
||||
if (typeof obj.msg === 'string') return obj.msg;
|
||||
try {
|
||||
return JSON.stringify(err);
|
||||
} catch {
|
||||
return '[unknown error object]';
|
||||
const allKeys = [...Object.keys(obj), ...Object.getOwnPropertyNames(obj)];
|
||||
for (const key of allKeys) {
|
||||
const val = obj[key];
|
||||
if (typeof val === 'string' && val.length > 0) {
|
||||
return `${key}: ${val}`;
|
||||
}
|
||||
}
|
||||
try {
|
||||
const str = JSON.stringify(err, Object.getOwnPropertyNames(err));
|
||||
if (str !== '{}') return str;
|
||||
} catch {}
|
||||
return `[error object with keys: ${allKeys.join(', ') || 'none'}]`;
|
||||
}
|
||||
return String(err);
|
||||
}
|
||||
|
||||
@@ -69,6 +76,14 @@ export class Enclave {
|
||||
this.log(`generate: created DID ${output.did}`);
|
||||
return output;
|
||||
} catch (err) {
|
||||
console.error('[DEBUG] Raw error:', err);
|
||||
console.error('[DEBUG] typeof:', typeof err);
|
||||
console.error('[DEBUG] constructor:', err?.constructor?.name);
|
||||
if (typeof err === 'object' && err !== null) {
|
||||
console.error('[DEBUG] keys:', Object.keys(err));
|
||||
console.error('[DEBUG] ownProps:', Object.getOwnPropertyNames(err));
|
||||
console.error('[DEBUG] prototype:', Object.getPrototypeOf(err));
|
||||
}
|
||||
const errMsg = extractErrorMessage(err);
|
||||
this.log(`generate: failed - ${errMsg}`, 'error');
|
||||
throw new Error(`generate: ${errMsg}`);
|
||||
|
||||
Reference in New Issue
Block a user