Improve error reporting around authorization.

pull/5370/head
Evan Sangaline 10 months ago committed by Aniket
parent 565ec34145
commit 0ea9417dd6
  1. 33
      libs/remix-ws-templates/src/script-templates/sindri/utils.ts

@ -36,7 +36,7 @@ const normalizePath = (path: string): string => {
* @returns {CircuitInfoResponse} compiled circuit * @returns {CircuitInfoResponse} compiled circuit
*/ */
export const compile = async (tags: string | string[] | null = ['latest']): CircuitInfoResponse => { export const compile = async (tags: string | string[] | null = ['latest']): CircuitInfoResponse => {
authorize() await authorize()
const sindriManifest = await getSindriManifest() const sindriManifest = await getSindriManifest()
// Create a map from file paths to `File` objects for all files in the workspace. // Create a map from file paths to `File` objects for all files in the workspace.
@ -73,13 +73,24 @@ export const compile = async (tags: string | string[] | null = ['latest']): Circ
console.log(`Compiling circuit "${sindriManifest.name}"...`) console.log(`Compiling circuit "${sindriManifest.name}"...`)
const files = Object.values(filesByPath) const files = Object.values(filesByPath)
const circuitResponse = await sindriClient.createCircuit(files, tags) try {
if (circuitResponse.status === 'Ready') { const circuitResponse = await sindriClient.createCircuit(files, tags)
console.log(`Circuit compiled successfully, circuit id: ${circuitResponse.circuit_id}`) if (circuitResponse.status === 'Ready') {
} else { console.log(`Circuit compiled successfully, circuit id: ${circuitResponse.circuit_id}`)
console.error('Circuit compilation failed:', circuitResponse.error || 'Unknown error') } else {
console.error('Circuit compilation failed:', circuitResponse.error || 'Unknown error')
}
return circuitResponse
} catch (error) {
if ('status' in error && error.status === 401) {
const message = 'Sindri API key authentication failed, please check that your key is correct in the settings.'
console.error(message)
throw new Error(message)
} else {
console.error('Unknown error occurred.')
throw error
}
} }
return circuitResponse
} }
/** /**
@ -89,7 +100,7 @@ export const compile = async (tags: string | string[] | null = ['latest']): Circ
* @returns {ProofInfoResponse} The generated proof. * @returns {ProofInfoResponse} The generated proof.
*/ */
export const prove = async (signals: {[id: string]: number | string}): ProofInfoResponse => { export const prove = async (signals: {[id: string]: number | string}): ProofInfoResponse => {
authorize() await authorize()
const sindriManifest = await getSindriManifest() const sindriManifest = await getSindriManifest()
const circuitName = sindriManifest.name const circuitName = sindriManifest.name
@ -103,7 +114,11 @@ export const prove = async (signals: {[id: string]: number | string}): ProofInfo
} }
return proofResponse return proofResponse
} catch (error) { } catch (error) {
if ('status' in error && error.status === 404) { if ('status' in error && error.status === 401) {
const message = 'Sindri API key authentication failed, please check that your key is correct in the settings.'
console.error(message)
throw new Error(message)
} else if ('status' in error && error.status === 404) {
const message = `No compiled circuit "${circuitName}" found, have you successfully compiled the circuit?` const message = `No compiled circuit "${circuitName}" found, have you successfully compiled the circuit?`
console.error(message) console.error(message)
throw new Error(message) throw new Error(message)

Loading…
Cancel
Save