Skip to content

Commit e00cab9

Browse files
committed
fix: Improve error for tag resolution error on null value (#616)
1 parent 2a841cc commit e00cab9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/stringify/stringify.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ function getTagObject(tags: Array<ScalarTag | CollectionTag>, item: Node) {
109109
}
110110

111111
if (!tagObj) {
112-
const name = (obj as any)?.constructor?.name ?? typeof obj
112+
const name =
113+
(obj as any)?.constructor?.name ?? (obj === null ? 'null' : typeof obj)
113114
throw new Error(`Tag not resolved for ${name} value`)
114115
}
115116
return tagObj

tests/doc/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,12 @@ describe('schema changes', () => {
12251225
expect(() => String(doc)).toThrow(/Tag not resolved for Date value/)
12261226
})
12271227

1228+
test('fail for missing null type (#616)', () => {
1229+
const doc = parseDocument('foo:')
1230+
doc.setSchema('1.2', { schema: 'failsafe' })
1231+
expect(() => String(doc)).toThrow(/Tag not resolved for null value/)
1232+
})
1233+
12281234
test('set schema + custom tags', () => {
12291235
const doc = parseDocument('foo: 1971-02-03T12:13:14', {
12301236
version: '1.1'

0 commit comments

Comments
 (0)