[1.1.4] functions like click should should throw exception with wrong target type

Bug #1382653 reported by RaiMan
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SikuliX
In Progress
Medium
RaiMan

Bug Description

Probably i'm stupid, but twice now I've tried to call

region.click(rect)

where rect is java.awt.Rectangle, which is not a supported target type.

The function simply does nothing and returns 0 (which i ignore).

Don't you suppose it would be better if it throws FindFailed? or else UnsupportedTargetType?

  private <PSIMRL> Location getLocationFromTarget(PSIMRL target) throws FindFailed {
    if (target instanceof Pattern || target instanceof String || target instanceof Image) {
      Match m = find(target);
      if (m != null) {
        if (isOtherScreen()) {
          return m.getTarget().setOtherScreen(scr);
        } else {
          return m.getTarget();
        }
      }
      return null; <======== SHOULD BE A THROW FINDFAILED
    }
    if (target instanceof Match) {
      return ((Match) target).getTarget();
    }
    if (target instanceof Region) {
      return ((Region) target).getCenter();
    }
    if (target instanceof Location) {
      return new Location((Location) target);
    }
    return null; <======== SHOULD BE A THROW BAD TARGET TYPE
  }

I can't see any situation where return null is helpful. I think a throw is better.

RaiMan (raimund-hocke)
Changed in sikuli:
status: New → Fix Committed
importance: Undecided → High
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.2.0
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 2.0.0 → 1.1.4
RaiMan (raimund-hocke)
summary: - [request] Sikuli functions like click should accept
- java.awt.Rectangle/Point as parameter
+ [1.1.4] functions like click should should throw exception with wrong
+ target type
RaiMan (raimund-hocke)
Changed in sikuli:
status: Fix Committed → In Progress
importance: High → Medium
milestone: 1.1.4 → 2.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.