Skip to content

Commit 449235a

Browse files
erbridgezeke
andcommitted
Improve error message from invalid input
Co-authored-by: Zeke Sikelianos <[email protected]>
1 parent b4b2d93 commit 449235a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/ReplicateClient.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export default class ReplicateClient {
2828
const nameComponents = /^([\w-]+)\/([\w-]+)$/.exec(nameOrParams);
2929

3030
if (!nameComponents) {
31-
throw new ReplicateError(`Invalid name: ${nameOrParams}`);
31+
throw new ReplicateError(
32+
`Invalid model name: ${nameOrParams}. This should be a string in the format {owner}/{name} or an object with owner and name strings.`
33+
);
3234
}
3335

3436
[, owner, name] = nameComponents;
@@ -39,7 +41,9 @@ export default class ReplicateClient {
3941
const nameComponents = /^([\w-]+)\/([\w-]+)$/.exec(nameOrParams.name);
4042

4143
if (!nameComponents) {
42-
throw new ReplicateError(`Invalid name: ${nameOrParams.name}`);
44+
throw new ReplicateError(
45+
`Invalid model name: ${nameOrParams}. This should be a string in the format {owner}/{name} or specify both owner and name strings in the parameter object.`
46+
);
4347
}
4448

4549
[, owner, name] = nameComponents;
@@ -61,7 +65,9 @@ export default class ReplicateClient {
6165
const idComponents = /^([\w-]+)\/([\w-]+)@(\w+)$/.exec(idOrParams);
6266

6367
if (!idComponents) {
64-
throw new ReplicateError(`Invalid ID: ${idOrParams}`);
68+
throw new ReplicateError(
69+
`Invalid model ID: ${idOrParams}. This should be a string in the format {owner}/{name}@{version} or an object with owner, name, and version strings.`
70+
);
6571
}
6672

6773
[, owner, name, version] = idComponents;
@@ -73,7 +79,9 @@ export default class ReplicateClient {
7379
const nameComponents = /^([\w-]+)\/([\w-]+)$/.exec(idOrParams.name);
7480

7581
if (!nameComponents) {
76-
throw new ReplicateError(`Invalid name: ${idOrParams.name}`);
82+
throw new ReplicateError(
83+
`Invalid model name: ${idOrParams.name}. This should be a string in the format {owner}/{name} or specify both owner and name strings in the parameter object.`
84+
);
7785
}
7886

7987
[, owner, name] = nameComponents;

0 commit comments

Comments
 (0)