op-vscode icon indicating copy to clipboard operation
op-vscode copied to clipboard

Error reading 'reference' when saving a single URL field

Open mlorenz-tug opened this issue 3 years ago • 4 comments

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

  1. Highlight an URL in a file which one wants to save (e.g. https://google.com)
  2. Call the 1Password: Save in 1Password command
  3. When asked input a name for the new item (e.g. my-url)
  4. When asked leave the auto-detected field name url
  5. Hit enter to save the URL in 1Password

What happened?

  1. The command 1Password: Save in 1Password results in an error: Cannot read properties of undefined (reading 'reference').
  2. The item is created in 1Password itself with the correct field name and value
  3. In VSCode the now saved URL is not replaced with a reference

What did you expect to happen?

  1. 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"}

mlorenz-tug avatar Oct 19 '22 07:10 mlorenz-tug

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.

jodyheavener avatar Oct 19 '22 17:10 jodyheavener

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

jodyheavener avatar Sep 20 '23 20:09 jodyheavener

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.

jodyheavener avatar May 23 '24 17:05 jodyheavener

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.

jodyheavener avatar May 23 '24 17:05 jodyheavener

This is now released in v1.0.5.

jodyheavener avatar Jul 16 '24 17:07 jodyheavener