JSON exception on "damlhub workspace install" command

Hi,

I’m writing a script that meant to create a new canton ledger on remote hub.daml.com cloud.

Following commands in bold passes successfully while the last one fails (“damlhub -j workspace install”):

damlhub token $accountToken
damlhub workspace
damlhub ledger create $projectId $ledgerName
curl -s https://api.hub.daml.com/api/ledger/${LEDGER_ID}/healthz (verifying that the ledger is up via REST)
damlhub ledger party $ledgerId $partyName
damlhub -j workspace upload $darFullPath
damlhub -j workspace install $darName $ledgerId

The error thrown in CLI is:

damlhub -j workspace install models-0.0.1.dar kui8ilu2ijax3496
2022-12-01 19:26:31,913 ERROR [api] [ERROR] A non-JSON response was returned
Message:        `something went wrong`
Status: 500
Unexpected error: SyntaxError: Unexpected token s in JSON at position 0
    at JSON.parse (<anonymous>)
    at /usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:300:52
    at step (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:48:23)
    at Object.next (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:29:53)
    at fulfilled (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:20:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

I’m struggling to understand what i’m missing here.

From first glance at damlhub-cli home page i saw that damlhub install command receives other arguments from what i sent:

I sent:
damlhub -j workspace install $darName $ledgerId
Documenation states:
damlhub workspace install $ledgerId $artifactHash

Is this might be the reason for this JSON Parse error?

P.S - I use latest damlhub-cli version: 0.0.1-alpha.11

Please advise
Thanks

Hi @ronih ,

To deploy a DAR to a ledger, try this:

damlhub workspace install {file_name} {ledger_id}
# Then retrieve the `artifact_hash` field from the JSON that returns
damlhub deployDar {ledger_id} {artifact_hash}

If the file remains the same, the artifact_hash will not change for future ledgers.

Let us know if that works.

Thanks,
Alex

Thanks @alex.graham ,

I used the same command syntax as you wrote.
This is what led me to the JSON exception i posted.

Here it is again:

Command:
damlhub -j workspace install ./daml/dist/models-0.0.1.dar kui8ilu2ijax3496

Output:

2022-12-01 20:39:55,347 ERROR [api] [ERROR] A non-JSON response was returned
Message:        `404: Not Found`
Status: 404
Unexpected error: SyntaxError: Unexpected token : in JSON at position 3
    at JSON.parse (<anonymous>)
    at /usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:300:52
    at step (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:48:23)
    at Object.next (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:29:53)
    at fulfilled (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:20:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Ah, sorry - I forgot to note, for that particular command, you currently need to run it in the same directory as the dar file.

Thanks @alex.graham

Same phenomena. JSON Exception upon damlhub install command.

Triggering the command from within the DAR directory hasn’t made an improvment.

Should i maybe re-create the dar? What is the source of the Exception? Is it the remote ledger or the damlhub client itself?

Output again:

2022-12-02 07:46:53,917 ERROR [api] [ERROR] A non-JSON response was returned
Message:        `something went wrong`
Status: 500
Unexpected error: SyntaxError: Unexpected token s in JSON at position 0
    at JSON.parse (<anonymous>)
    at /usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:300:52
    at step (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:48:23)
    at Object.next (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:29:53)
    at fulfilled (/usr/local/lib/node_modules/damlhub-cli/lib/src/dabl/apiRequest.js:20:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)