Skip to content

[Development] Improvements in Error tracing #110

Description

@TanmoySG

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions