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
In this repro, I stored a Date object using update, and later attempted to retrieve the value using get<Date>.
const KEY = 'TEST_TIMESTAMP_KEY';
let value = context.globalState.get<Date>(KEY);
if (value === undefined) {
context.globalState.update(KEY, new Date());
value = context.globalState.get<Date>(KEY);
}
console.log(`TEST_TIMESTAMP_KEY = ${value} type=${typeof value}`);
if (value === undefined || !(value instanceof Date)) {
throw Error(`unexpected date - ${value}`);
}
The first round (immediately storing the value) works as expected, except that the value doesn't match the usual ISO 8601 format (JSON.stringify returns)
Congratulations, your extension "helloworld-sample" is now active!
extensionHostProcess.js:144
"2024-04-03T19:24:17.476Z"
extensionHostProcess.js:144
TEST_TIMESTAMP_KEY = Wed Apr 03 2024 15:24:17 GMT-0400 (Eastern Daylight Time) type=object
Restart the extension. Now this time, the error will be thrown, because context.globalState.get<Date>(KEY) is not a Date object. It's string. I am guessing get failed to parse the persisted JSON string (ISO 8601 format), and silently returned a string object.
Congratulations, your extension "helloworld-sample" is now active!
extensionHostProcess.js:144
"2024-04-03T19:25:06.045Z"
extensionHostProcess.js:144
TEST_TIMESTAMP_KEY = 2024-04-03T19:24:17.478Z type=string
(and crash)
I think this code used to work last year, but recently, we started to notice problems caused by this asymmetry.
Did Memento API get changed recently?
The text was updated successfully, but these errors were encountered:
I expected Memento's
get
to recover the JSON-stringifyable object but it doesn't always.Repro: hyangah/vscode-extension-samples@194f02e
In this repro, I stored a
Date
object usingupdate
, and later attempted to retrieve the value usingget<Date>
.The first round (immediately storing the value) works as expected, except that the value doesn't match the usual ISO 8601 format (JSON.stringify returns)
Restart the extension. Now this time, the error will be thrown, because
context.globalState.get<Date>(KEY)
is not aDate
object. It's string. I am guessingget
failed to parse the persisted JSON string (ISO 8601 format), and silently returned a string object.I think this code used to work last year, but recently, we started to notice problems caused by this asymmetry.
Did Memento API get changed recently?
The text was updated successfully, but these errors were encountered: