Urgent.News

What's breaking now, across thousands of outlets.

Tech

The Counter That Counted a Call the Preflight Never Reached

This is a submission for DEV's Summer Bug Smash: Clear the Lineup , powered by Sentry . Project Overview I was working on a small Python component that performs a preflight check and then, if the check succeeds, invokes one synchronous operation callback. A counter records whether that callback invocation returned normally. The counter is used for diagnostics, so it must follow the control flow…

The bug fix story revolves around a Python component that conducts a preflight check and subsequently executes a synchronous operation callback if the check is successful. The purpose of a counter is to record whether the callback's invocation proceeded normally, crucial for diagnostics. However, the previous implementation incorrectly returned 1 in cases where a handled failure occurred.

This discrepancy arose because the successful path was anticipated to invoke exactly one operation. If the preflight check failed, the operation was never entered, and the function still returned 1, contradicting the actual control flow.

Upon investigation, the old behavior could be summarized as: if preflight succeeded and operation succeeded, return 1; otherwise, return 1 regardless of what happened. The core fix introduced a straightforward change: a handled failure directly returns 0, while the only way to return 1 is when the operation callback invocation completes normally. This change ensures that observed control flow, rather than expected control flow, guides the counter's behavior.

The regression assertion verifies that when the preflight function raises an exception before calling the operation, completed_calls returns 0. This assertion holds under various conditions, including under normal Python execution and with optimizations enabled. The counter's purpose is to measure returns from normal callback invocations, not remote side effects or deferred work.

It's designed for synchronous application code in a single process, not a sandbox for potentially harmful callbacks. Ultimately, this bug fix ensures that a preflight failure won't falsely report a completed call.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Don't validate the output. Validate that you were allowed to generate it.

Introduction I run a site that collects overseas viewer comments about individual anime episodes, translates them, and publishes them. It updates automatically every day. There is one failure mode that matters more than all the others: creating a page for an episode that has not aired yet.

  • Check function compares claimed air date with observed date from MyAnimeList (MAL)
  • Five-day tolerance accounts for time zones and streaming delays
  • Early exit if any episode fails air date check to prevent false information generation

More from Sunday 23 August →