Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backup storage by looking at the options correctly #13983

Merged
merged 3 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/13981.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Backup on custom editors is being ignored.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class NativeEditorStorage implements INotebookStorage {
// Attempt to read the contents if a viable file
const contents = NativeEditorStorage.isUntitledFile(file) ? possibleContents : await this.fs.readFile(file);

const skipDirtyContents = typeof options === 'boolean' ? options : !!options;
const skipDirtyContents = typeof options === 'boolean' ? options : !options || options.length === 0;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root cause of the problem was the !!options was the opposite of what we wanted. This would turn an options into a true, whereas we really wanted any options to turn it into a false.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aahg, the problem was options was an empty array.

Copy link
Member

@IanMatthewHuff IanMatthewHuff Sep 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going to lie. I find lines 279 - 282 really hard to read.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's really why this bug happened. The skipDirtyContents and the backupId are both confusing. I think it would have been better to just add another argument to the function instead of having the overload.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel unclean just reading the function signature. I guess it's ok. Maybe we could distinctly split on if the options is a bool or a string and put it in a local variable name that actually makes sense?

if (typeof options === 'boolean') {
// assign to skipDirtyContents
} else if (typeof options === 'string') {
// assign to backupId
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, @IanMatthewHuff suggestion will improve readability significantly

// Use backupId provided, else use static storage key.
const backupId =
typeof options === 'string' ? options : skipDirtyContents ? undefined : this.getStaticStorageKey(file);
Expand Down