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

[Bug] err not returned in Func LoadPolicyArray #1083

Closed
GerryLon opened this issue Aug 21, 2022 · 9 comments · Fixed by #1085
Closed

[Bug] err not returned in Func LoadPolicyArray #1083

GerryLon opened this issue Aug 21, 2022 · 9 comments · Fixed by #1085

Comments

@GerryLon
Copy link

Casbin version: v2.52.2
Bug: err not returned in Func LoadPolicyArray
企业微信截图_f722d946-f311-4426-8e5f-c231b9bb26f3

@casbin-bot
Copy link
Member

@tangyang9464 @JalinWang

@hsluoyz
Copy link
Member

hsluoyz commented Aug 21, 2022

@JalinWang plz work on it

/cc @tangyang9464

@GerryLon
Copy link
Author

GerryLon commented Aug 21, 2022

why not allow empty v5 field?
I use v5 field as a condition(value can be any string), empty v5 field means "any conditioin can pass(like any client ip)".
I think empty string as any condition is general.

@JalinWang
Copy link
Member

why not allow empty v5 field? I use v5 field as a condition(value can be any string), empty v5 field means "any conditioin can pass(like any client ip)". I think empty string as any condition is general.

@GerryLon Which adapter?

@GerryLon
Copy link
Author

GerryLon commented Aug 21, 2022

why not allow empty v5 field? I use v5 field as a condition(value can be any string), empty v5 field means "any conditioin can pass(like any client ip)". I think empty string as any condition is general.

@GerryLon Which adapter?

github.com/casbin/mongodb-adapter/v3 v3.3.0

	"github.com/casbin/casbin/v2/persist"
	mongodbadapter "github.com/casbin/mongodb-adapter/v3"

@GerryLon
Copy link
Author

why not allow empty v5 field? I use v5 field as a condition(value can be any string), empty v5 field means "any conditioin can pass(like any client ip)". I think empty string as any condition is general.

@GerryLon Which adapter?

my main codes like below:

package auth

import (
  "github.com/casbin/casbin/v2"
  mongodbadapter "github.com/casbin/mongodb-adapter/v3"
)

func InitCasbin() {
  // 定义基于mongodb的casbin适配器
  adapter, err = mongodbadapter.NewAdapterWithClientOption(mongoClientOption, databaseName)
  if err != nil {
    log.ErrorContext(ctx, err)
    return nil, err
  }
  casbinModel, err = casbinmodel.NewModelFromString(mconf)
  if err != nil {
    log.ErrorContext(ctx, err)
    return nil, err
  }
  enforcer, err = casbin.NewSyncedEnforcer(casbinModel, adapter)
  if err != nil {
    log.ErrorContext(ctx, err)
    return nil, err
  }

  // load policy from db or file into memory
  if err = enforcer.LoadPolicy(); err != nil {
    log.ErrorContext(ctx, err)
    return nil, err
  }
}

when I debug above codes, in enforcer.LoadPolicy() -> ... -> LoadPolicyArray()` error is not nil:
image

@hsluoyz
Copy link
Member

hsluoyz commented Aug 21, 2022

why not allow empty v5 field? I use v5 field as a condition(value can be any string), empty v5 field means "any conditioin can pass(like any client ip)". I think empty string as any condition is general.

@GerryLon are you reporting a new issue other than this one? If yes, plz create a new issue here: https://github.com/casbin/mongodb-adapter/issues

@JalinWang
Copy link
Member

@JalinWang plz work on it

/cc @tangyang9464

@hsluoyz All the adapters depend on this function without error handling. Should we modify them all?

@hsluoyz
Copy link
Member

hsluoyz commented Aug 21, 2022

We can add error as return value, but the adapters don't need to be modified to handle the return value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants