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

check for missing did error and provide helpful error message #70

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
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
11 changes: 9 additions & 2 deletions packages/devtools/src/composite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { CeramicApi, SignedCommit } from '@ceramicnetwork/common'
import type { MissingDIDError } from '@ceramicnetwork/http-client'
import { Model, type ModelViewsDefinition } from '@ceramicnetwork/stream-model'

import { StreamID } from '@ceramicnetwork/streamid'
import type {
CompositeViewsDefinition,
Expand Down Expand Up @@ -541,11 +543,16 @@ export class Composite {

/**
* Configure the Ceramic node to index the models defined in the composite. An authenticated DID
* set as admin in the Ceramic node configuration must be attached to the Ceramic instance.
* set as admin in the Ceramic node configuration must be attached to the Ceramic instance, otherwise
* an error is thrown.
*/
async startIndexingOn(ceramic: CeramicApi): Promise<void> {
const modelIDs = Object.keys(this.#definition.models).map(StreamID.fromString)
await ceramic.admin.startIndexingModels(modelIDs)
try {
await ceramic.admin.startIndexingModels(modelIDs)
} catch(e: MissingDIDError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the only type of error that can happen please? What if the node is unreachable and there's a HTTP 404 error instead for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the purpose here is to make the error clearer specifically for missing did. other errors will continue to behave as they do now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I'm not sure I follow.
Here the e: MissingDIDError assumes that the thrown error can only be MissingDIDError, but that's not guarantied to be the cases, is it? What happens if the HTTP client throws another type of error, wouldn't the error message incorrectly refer to the missing DID when it can be other types of errors, like an incorrect Ceramic node endpoint or invalid model IDs input?

throw new Error(`${e.message}: is the environment variable DID_PRIVATE_KEY set to a valid DID?`)
}
}

/**
Expand Down