why this happens: UTC: 2025-06-05T22:37:19.216Z error: [Log 100748] Failed to validate…
- User
why this happens:
UTC: 2025-06-05T22:37:19.216Z error: [Log 100748] Failed to validate request-provided data against the known schema: Failed to standardize schema: Cannot read properties of undefined (reading 'error') UTC: 2025-06-05T22:37:19.216Z error: ❌ Error 422 in /api/v1/data_ingestion/upload_file: Failed to validate request-provided data against the known schema: Failed to standardize schema: Cannot read properties of undefined (reading 'error')
fromthis code: return { rawSchema: schema, supportedFileTypes: supportedFileTypes, dataSchema: dataSchema, transformationSchema: transformationSchema, }; } catch (error) { taskLogger.error(Failed to standardize schema: {error.message}); } }
why is "Cannot read properties of undefined (reading 'error')"
the error I know that occurs from getSchema in this line:
const standardizeSchema = async (ingestion_type, role_id, taskLogger) => { try { // get schema from DB according to ingestion_type and role_id let schema = await getSchema(role_id, ingestion_type);
and the getSchema itself looks like this: async function getSchema(role_id, ingestion_type, taskLogger) { try { const query = fs.readFileSync(path.join(__dirname, '../queries/dataIngestion/getSchema.sql'), 'utf8'); const parameters = { role_id: role_id, ingestion_type: ingestion_type } // log query let formatted = db.formatQuery(query, parameters); const result = await db.query2(query, parameters); if (!result?.rows?.length) { taskLogger.info(Executed query: {role_id} and ingestion_type: ${ingestion_type}. No rows returned.); } const raw = result.rows[0].template_content;
try { const parsed = JSON.parse(raw); return parsed; } catch (err) { throw new Error(Failed to parse schema (template_content) from db as JSON: ${err.message}); } } catch (error) { taskLogger.error(Failed to get schema from db: ${error.message}, { role_id, ingestion_type }); throw new Error(Failed to get schema from db: ${error.message}); }}
the issue that is happening is indeed some parsing issue so shouldn't it be throwing an 'Error' object as seen here? SHORT
- Assistant
Short answer:
Yes, your code should be throwing anErrorobject, but the root cause of"Cannot read properties of undefined (reading 'error')"is that somewhere in your code, you are trying to access.erroron an object that is actuallyundefined.Why this happens:
- In your
catchblocks, you doerror.message, which is fine iferroris always anErrorobject. - However, if something throws a non-Error value (e.g.,
throw undefined,throw null, orthrow "some string"), thenerrorwill not have a.messageproperty, anderror.messagewill itself throw:
Cannot read properties of undefined (reading 'message') - If your logger or error handler tries to access
.erroron an undefined object, you get:
Cannot read properties of undefined (reading 'error')
How to fix:
Always check that
erroris defined and has a.messageproperty:catch (error) { const msg = error && error.message ? error.message : String(error); taskLogger.error(`Failed to standardize schema: ${msg}`, { role_id, ingestion_type }); throw new Error(`Failed to standardize schema: ${msg}`); }And do the same in all your catch blocks.
Why it happens in your case:
- If
JSON.parse(raw)fails, it throws a realError. - But if anywhere else in your code, something throws
undefinedor a non-Error, your catch block will break as above. - Or, if your logger expects an object with an
.errorproperty, but you passundefined, you get this error.
Summary:
Your code assumes all thrown errors areErrorobjects. In JS, that's not always true. Defensive coding in your catch blocks will prevent this. - In your
- User
both are shit
- Assistant
I get your frustration—JavaScript’s error handling can be really annoying, especially when you expect errors to always be
Errorobjects, but sometimes they’re not. This leads to confusing bugs like the one you’re seeing.If you want a quick, robust fix:
Just always coerce the error to a string, so your logging and error handling never break, no matter what gets thrown:catch (error) { const msg = (error && error.message) ? error.message : JSON.stringify(error); taskLogger.error(`Failed to standardize schema: ${msg}`, { role_id, ingestion_type }); throw new Error(`Failed to standardize schema: ${msg}`); }Or, even more defensively:
catch (error) { const msg = error?.message || String(error); taskLogger.error(`Failed to standardize schema: ${msg}`, { role_id, ingestion_type }); throw new Error(`Failed to standardize schema: ${msg}`); }Bottom line:
- JavaScript lets you throw anything, not just
Errorobjects. - Defensive error handling saves you from these headaches.
If you want to vent more or need a more elegant solution, let me know!
- JavaScript lets you throw anything, not just
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.