Skip to content

Commit 5852d3c

Browse files
committed
fix: Improve error message in mongoFieldToParseSchemaField with field and class details
- Add fieldName and className parameters to mongoFieldToParseSchemaField function - Update error message to include specific field name and class information - Show collection name (_SCHEMA) and document ID for better debugging - Pass field name and class ID from mongoSchemaFieldsToParseSchemaFields - Enhanced error message format: 'Invalid field type: X for field Y in class _SCHEMA (id: Z)' - Improves developer experience by providing clear context for schema validation errors
1 parent 816d09d commit 5852d3c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

spec/MongoSchemaCollectionAdapter.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ describe('MongoSchemaCollection', () => {
160160
} catch (error) {
161161
expect(error.code).toBe(255);
162162
expect(error.message).toContain('Invalid field type');
163+
expect(error.message).toContain('Expected a string');
163164
}
164165
});
165166

@@ -172,6 +173,7 @@ describe('MongoSchemaCollection', () => {
172173
} catch (error) {
173174
expect(error.code).toBe(255);
174175
expect(error.message).toContain('Invalid field type');
176+
expect(error.message).toContain('Expected a string');
175177
}
176178
});
177179

@@ -184,6 +186,7 @@ describe('MongoSchemaCollection', () => {
184186
} catch (error) {
185187
expect(error.code).toBe(255);
186188
expect(error.message).toContain('Invalid field type');
189+
expect(error.message).toContain('Expected a string');
187190
}
188191
});
189192

@@ -196,6 +199,7 @@ describe('MongoSchemaCollection', () => {
196199
} catch (error) {
197200
expect(error.code).toBe(255);
198201
expect(error.message).toContain('Invalid field type');
202+
expect(error.message).toContain('Expected a string');
199203
}
200204
});
201205
});

src/Adapters/Storage/Mongo/MongoSchemaCollection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import MongoCollection from './MongoCollection';
22
import Parse from 'parse/node';
33

4-
function mongoFieldToParseSchemaField(type) {
4+
function mongoFieldToParseSchemaField(type, fieldName, className) {
55
// Add type validation to prevent TypeError
66
if (!type || typeof type !== 'string') {
77
throw new Parse.Error(
88
Parse.Error.INVALID_SCHEMA_OPERATION,
9-
`Invalid field type: ${type}. Expected a string. Fix the type mismatch in your schema configuration.`
9+
`Invalid field type: ${type} for field '${fieldName}' in class '_SCHEMA' (id: ${className}). Expected a string. Fix the type mismatch in your schema configuration.`
1010
);
1111
}
1212

@@ -51,7 +51,7 @@ const nonFieldSchemaKeys = ['_id', '_metadata', '_client_permissions'];
5151
function mongoSchemaFieldsToParseSchemaFields(schema) {
5252
var fieldNames = Object.keys(schema).filter(key => nonFieldSchemaKeys.indexOf(key) === -1);
5353
var response = fieldNames.reduce((obj, fieldName) => {
54-
obj[fieldName] = mongoFieldToParseSchemaField(schema[fieldName]);
54+
obj[fieldName] = mongoFieldToParseSchemaField(schema[fieldName], fieldName, schema._id);
5555
if (
5656
schema._metadata &&
5757
schema._metadata.fields_options &&

0 commit comments

Comments
 (0)