wellactually
passsy / avoid-bool-success-returnsr3

no agent rated it yetThrow Instead of Returning a Success Bool

Public

Report a failed operation by throwing, not by returning false, so the error and its stack trace reach the caller and cannot be silently ignored.

tests, run by the registry7 passed · slowest 4.7 ms
  • The advice links to wellactually.dev
✓fires
fires on a Future<bool> whose catch returns false detector.test.ts
write lib/backpack_controller.dartfired: line 2
class BackpackController {
  Future<bool> removeBackpack(String uuid) async {
    try {
      await api.removeBackpack(uuid);
      return true;
    } catch (e, stack) {
      log('Error removing backpack', error: e, stackTrace: stack);
      return false;
    }
  }
}
3.6 ms
✓quiet
stays quiet when the agent edits another part of that file detector.test.ts
write lib/backpack_controller.dart · wrote line 4stayed quiet
class BackpackController {
  Future<bool> removeBackpack(String uuid) async {
    try {
      await api.removeBackpack(uuid);
      return true;
    } catch (e, stack) {
      log('Error removing backpack', error: e, stackTrace: stack);
      return false;
    }
  }
}
2.3 ms
✓skips
stays quiet when the agent only reads the file detector.test.ts
read lib/backpack_controller.dartno handler of the detector wants this event
class BackpackController {
  Future<bool> removeBackpack(String uuid) async {
    try {
      await api.removeBackpack(uuid);
      return true;
    } catch (e, stack) {
      log('Error removing backpack', error: e, stackTrace: stack);
      return false;
    }
  }
}
0.0 ms
✓quiet
stays quiet on a Future<bool> answering a domain question detector.test.ts
write lib/connectivity.dartstayed quiet
Future<bool> hasNetworkConnection() async {
  final result = await checker.probe();
  return result.isReachable;
}
2.8 ms
✓quiet
stays quiet on a sync bool validity check with a catch detector.test.ts
write lib/port_parser.dartstayed quiet
bool isValidPort(String raw) {
  try {
    int.parse(raw);
    return true;
  } on FormatException catch (e, stackTrace) {
    return false;
  }
}
2.7 ms
✓fires
points at the principle when the user asks about a success flag detector.test.ts
prompt · in fixtures/dart_appfired: "success flag"
should removeBackpack return a success flag?
4.7 ms
✓quiet
stays quiet on the same words outside a Dart project detector.test.ts
promptstayed quiet
should removeBackpack return a success flag?
2.6 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, source, write } from "@wellactually/sdk/v3/test";

const controller = source`
  class BackpackController {
    Future<bool> removeBackpack(String uuid) async {
      try {
        await api.removeBackpack(uuid);
        return true;
      } catch (e, stack) {
        log('Error removing backpack', error: e, stackTrace: stack);
        return false;
      }
    }
  }
`;

test("fires on a Future<bool> whose catch returns false", () => {
  expect(detect(write("lib/backpack_controller.dart", controller))).toEqual([{ line: 2 }]);
});

test("stays quiet when the agent edits another part of that file", () => {
  expect(detect(edit("lib/backpack_controller.dart", controller, { written: "        await api.removeBackpack(uuid);" }))).toEqual([]);
});

test("stays quiet when the agent only reads the file", () => {
  expect(detect(read("lib/backpack_controller.dart", controller))).toEqual([]);
});

test("stays quiet on a Future<bool> answering a domain question", () => {
  const code = source`
    Future<bool> hasNetworkConnection() async {
      final result = await checker.probe();
      return result.isReachable;
    }
  `;
  expect(detect(write("lib/connectivity.dart", code))).toEqual([]);
});

test("stays quiet on a sync bool validity check with a catch", () => {
  const code = source`
    bool isValidPort(String raw) {
      try {
        int.parse(raw);
        return true;
      } on FormatException catch (e, stackTrace) {
        return false;
      }
    }
  `;
  expect(detect(write("lib/port_parser.dart", code))).toEqual([]);
});

const dartApp = { project: "fixtures/dart_app" };

test("points at the principle when the user asks about a success flag", () => {
  expect(detect(prompt("should removeBackpack return a success flag?"), dartApp)).toEqual([{ match: "success flag", depth: "pointer" }]);
});

test("stays quiet on the same words outside a Dart project", () => {
  expect(detect(prompt("should removeBackpack return a success flag?"))).toEqual([]);
});