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

Inconsistency in Ensure*(...) functions #648

Open
Kafkalasch opened this issue Jan 21, 2025 · 0 comments
Open

Inconsistency in Ensure*(...) functions #648

Kafkalasch opened this issue Jan 21, 2025 · 0 comments

Comments

@Kafkalasch
Copy link

Hi,

I stumbled across some inconsistencies for the various Ensure*(...) methods.

E.g.

func (d databaseAnalyzer) EnsureAnalyzer(ctx context.Context, analyzer *AnalyzerDefinition) (bool, Analyzer, error) {
	...
	switch code := resp.Code(); code {
	case http.StatusCreated, http.StatusOK:
		return code == http.StatusOK, newAnalyzer(d.db, response.AnalyzerDefinition), nil
	default:
		return false, nil, response.AsArangoErrorWithCode(code)
	}
}

will return true if the analyzer already existed.

func (c *collectionIndexes) EnsurePersistentIndex(ctx context.Context, fields []string, options *CreatePersistentIndexOptions) (IndexResponse, bool, error) {
       ....
	exist, err := c.ensureIndex(ctx, &reqData, &result)
	return newIndexResponse(&result), exist, err
}

func (c *collectionIndexes) ensureIndex(ctx context.Context, reqData interface{}, result interface{}) (bool, error) {
	
	switch code := resp.Code(); code {
	case http.StatusOK:
		return false, nil
	case http.StatusCreated:
		return true, nil
	default:
		return false, response.AsArangoErrorWithCode(code)
	}
}

will return true if the index was created. So it is the other way around.

This is especially misleading, as the variable in the code is called "exist", which is true if it was created and false if it already existed.

I did not check the other, similar methods.

Also: The return order is mixed up. Introducing some consistency here, would make it easier to use the library without the need of digging into the implementation each time something unexpected happens.

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