appwrite: 🐛 Bug Report: Incorrect Error Handling When Passing Int as documentId parameter

👟 Reproduction steps

When attempting to pass an unsupported type property (in this case, an int) when creating a Document, the response erroneously declares:

error: AppwriteException: Invalid documentId param: Parameter must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char

Example code:

import { Client, Databases, ID } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1')
    .setProject('<PROJECT_ID>');
const databases = new Databases(client);
const id = Date.now(); //this does not work, error recieved is shown after code ends
const promise = databases.createDocument(
    '[DATABASE_ID]',
    '[COLLECTION_ID]',
    id,
    data
);

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});

While the code is incorrect, the error returned does not accurately reflect the actual issue. The value returned is a epoch timestamp as an int. This is fixed by modifying the id generation to a string: const id = Date.now().toString()

👍 Expected behavior

We need to to improve error handling and return the appropriate error when passing an unsupported type and clarify it must be a string.

👎 Actual Behavior

Error returns as Invalid documentId param: Parameter must contain at most 36 chars.

🎲 Appwrite version

Appwrite Cloud

💻 Operating system

Linux

🧱 Your Environment

n/a

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn’t find similar issue

🏢 Have you read the Code of Conduct?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 25 (11 by maintainers)

Most upvoted comments

I want to work on it. I am raising the PR soon

@Ayush9026 assigned! Thanks for your interest! 🙏