Error reading 'reference' when saving a single URL field
Your environment
op-vscode version: v1.0.2
VS Code version: 1.72.2
CLI version: 2.7.1
OS: Ubuntu 20.04.5 LTS
Steps to reproduce
- Highlight an URL in a file which one wants to save (e.g.
https://google.com) - Call the
1Password: Save in 1Passwordcommand - When asked input a name for the new item (e.g.
my-url) - When asked leave the auto-detected field name
url - Hit enter to save the URL in 1Password
What happened?
- The command
1Password: Save in 1Passwordresults in an error:Cannot read properties of undefined (reading 'reference'). - The item is created in 1Password itself with the correct field name and value
- In VSCode the now saved URL is not replaced with a reference
What did you expect to happen?
- The saved URL should be replaced with the 1Password reference
Notes & Logs
When naming the field something other than url (e.g. be_url) it will work as expected!
[2022-10-19 09:37:08.697] [exthost] [error] TypeError: Cannot read properties of undefined (reading 'reference')
at /home/administrator/.vscode/extensions/1password.op-vscode-1.0.2/dist/extension.js:53:6022
at Object.edit (/usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:90:53153)
at Ct.insertSavedItem (/home/administrator/.vscode/extensions/1password.op-vscode-1.0.2/dist/extension.js:53:6000)
at Ct.saveItem (/home/administrator/.vscode/extensions/1password.op-vscode-1.0.2/dist/extension.js:53:4345)
at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /home/administrator/.vscode/extensions/1password.op-vscode-1.0.2/dist/extension.js:53:2298
at async n._executeContributedCommand (/usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:90:111316) op-vscode.saveValueToItem {"value":"1Password.op-vscode","_lower":"1password.op-vscode"}
Thanks for filing this @mlorenz-tug, I can reproduce it on my end.
This issue is occurring because when you create a field with the label url it creates a special URL-type field on the item. This results in that field getting excluded from the regular "fields" property and added to a separate "urls" property in the JSON response of the CLI command happening in the background. I've filed an issue with the team to address this.
As this is coming up for work, I think this is the area we should be looking at: https://github.com/1Password/op-vscode/blob/main/src/items.ts#L355-L367
Circling back to this issue.
The current blocker is that an item's "website" isn't considered a field, and cannot be accessed via secret reference. I'm working with the appropriate teams to try and find a resolution.
As a stop-gap I have updated the default field label for URLs to "address". A field label of "website" or "url" will result in the value being stored as an item's main URL, but a field label of "address" will not.
This is now released in v1.0.5.