Skip to content

Commit

Permalink
merge master -Dorg -Ssuccess-only: PR 266 (errors: use raise_error fr…
Browse files Browse the repository at this point in the history
…om cli plugins)
  • Loading branch information
snoopycrimecop committed Mar 24, 2022
2 parents b9440aa + df25060 commit 7d690a3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/omero/plugins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def _configure(self, parser):
HqlControl._configure(self, parser)
parser.set_defaults(func=self.search)

self.add_error("BAD_OBJECT", 431, "Bad object: %s")
self.add_error("ADMIN_ONLY", 432, "Only admin can index object")
self.add_error("NO_RESULTS", 433, "No results found.")
self.add_error("USAGE", 434, "usage: %s")

def date(self, user_string):
try:
t = time.strptime(user_string, "%Y-%m-%d")
Expand All @@ -96,7 +101,7 @@ def search(self, args):

if args.index:
if not self.ctx.get_event_context().isAdmin:
self.ctx.die(432, "Only admin can index object")
self.raise_error("ADMIN_ONLY")

try:
parts = args.type.split(":")
Expand All @@ -109,7 +114,7 @@ def search(self, args):
obj.setId(omero.rtypes.rlong(id))
except Exception as e:
self.ctx.dbg(e)
self.ctx.die(432, "Bad object: %s" % args.type)
self.raise_error("BAD_OBJECT", args.type)

c.sf.getUpdateService().indexObject(obj)

Expand Down Expand Up @@ -144,7 +149,7 @@ def search(self, args):
search.byFullText(args.query)

if not search.hasNext(ctx):
self.ctx.die(433, "No results found.")
self.raise_error("NO_RESULTS")

self.ctx.set("search.results", [])
while search.hasNext(ctx):
Expand All @@ -157,7 +162,7 @@ def search(self, args):
style=args.style,
idsonly=args.ids_only)
except omero.ApiUsageException as aue:
self.ctx.die(434, aue.message)
self.raise_error("USAGE", aue.message)

finally:
search.close()
Expand Down

0 comments on commit 7d690a3

Please sign in to comment.