You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The error message that is shown when a record runtype finds invalid keys is incorrect.
As far as I can see this bug was introduced in v7.0.0, specifically in commit 14bac166c.
Below are examples showing the incorrect error message in the current version (v7.1.2). See reproduction on replit.
import*asstfrom"simple-runtypes"constrecordRT=st.record({a: st.string()})console.log(st.use(recordRT,{a: "ay"}))// => { ok: true, result: { a: 'ay' } }constresult1=st.use(recordRT,{a: "ay",b: "bee"})console.log(result1)// => {// ok: false,// error: {// reason: 'invalid keys in record [{"a":"ay","b":"bee"}]',// path: [],// value: { a: 'ay', b: 'bee' },// [Symbol(SimpleRuntypesFail)]: true// }// }console.log(st.getFormattedError(result1.error))// (A)// => invalid keys in record [{"a":"ay","b":"bee"}] at `<value>` for `{"a":"ay","b":"bee"}`constnestedRecordRT=st.record({a: st.string(),b: st.record({c: st.string()})})console.log(st.use(nestedRecordRT,{a: "ay",b: {c: "cee"}}))// => { ok: true, result: { a: 'ay', b: { c: 'cee' } } }constresult2=st.use(nestedRecordRT,{a: "ay",b: {c: "cee",d: "dee"}})console.log(result2)// => {// ok: false,// error: {// reason: 'invalid keys in record [{"c":"cee","d":"dee"}]',// path: [ 'b' ],// value: { a: 'ay', b: [Object] },// [Symbol(SimpleRuntypesFail)]: true// }// }console.log(st.getFormattedError(result2.error))// (B)// => invalid keys in record [{"c":"cee","d":"dee"}] at `<value>.b` for `{"c":"cee","d":"dee"}`constresult3=st.use(nestedRecordRT,{a: "ay",b: {c: "cee"},e: "eee"})console.log(result3)// => {// ok: false,// error: {// reason: 'invalid keys in record [{"a":"ay","b":{"c":"cee"},"e":"eee"}]',// path: [],// value: { a: 'ay', b: [Object], e: 'eee' },// [Symbol(SimpleRuntypesFail)]: true// }// }console.log(st.getFormattedError(result3.error))// (C)// => invalid keys in record [{"a":"ay","b":{"c":"cee"},"e":"eee"}] at `<value>` for `{"a":"ay","b":{"c":"cee"},"e":"eee"}`
The error messages should read:
(A) invalid keys in record ["b"] at `<value>` for `{"a":"ay","b":"bee"}`
(B) invalid keys in record ["d"] at `<value>.b` for `{"c":"cee","d":"dee"}`
(C) invalid keys in record ["e"] at `<value>` for `{"a":"ay","b":{"c":"cee"},"e":"eee"}`
The text was updated successfully, but these errors were encountered:
The error message that is shown when a
record
runtype finds invalid keys is incorrect.As far as I can see this bug was introduced in v7.0.0, specifically in commit
14bac166c
.Below are examples showing the incorrect error message in the current version (v7.1.2). See reproduction on replit.
The error messages should read:
The text was updated successfully, but these errors were encountered: