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

[Development] Improvements in Error tracing #110

Open
TanmoySG opened this issue Apr 29, 2023 · 0 comments
Open

[Development] Improvements in Error tracing #110

TanmoySG opened this issue Apr 29, 2023 · 0 comments
Assignees

Comments

@TanmoySG
Copy link
Owner

wunderDB Error wdbErrors is currently constant, and error messages do not have the ability to show which field/entity/etc caused the error. For example, for Database Missing error (parent db for collection does not exist), the error is

	DatabaseDoesNotExistsError = WdbError{
		ErrCode:        "databaseMissing",
		ErrMessage:     "database with ID doesn't exist",
		HttpStatusCode: 404,
	}

Here ErrMessage is constant/fixed and does not include the id which might not exists. This can be modified to make the message as a format and adding the required ID at the caller level so that the message comes as database with ID [databaseId] doesn't exist.

Possible Fixes/Solutions

The error message can be made into a string format (wherever required, and just plain string wherever not required), eg:

	DatabaseDoesNotExistsError = WdbError{
		ErrCode:        "databaseMissing",
		ErrMessage:     "database with ID [%s] does not exist",
		HttpStatusCode: 404,
	}

Adding a Format(args) method on the wdbError struct to fill in the placeholders (%s / %i / %v) with the required value. Example

func (wdbe WdbError) Format(args ...interface{}) WdbError {
	wdbe.ErrMessage = fmt.Sprintf(wdbe.ErrMessage, args...)
	return wdbe
}

And at caller end

	if exists, _ := wdb.Databases.CheckIfExists(databaseId); !exists {
		return &er.DatabaseDoesNotExistsError.Format(databaseId)
	}

The function name Format can be different to much more specific like Fill or TBD

@TanmoySG TanmoySG self-assigned this Jun 12, 2023
@TanmoySG TanmoySG pinned this issue Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant