Conversation
…empt without knowing what's in it
birgelee
left a comment
There was a problem hiding this comment.
This looks good, thanks for the work.
| GENERAL_HTTP_ERROR = ('mpic_error:http', 'An HTTP error occurred: Response status {0}, Response reason: {1}') | ||
| INVALID_REDIRECT_ERROR = ('mpic_error:redirect:invalid', 'Invalid redirect. Redirect code: {0}, target: {1}') | ||
| COHORT_CREATION_ERROR = ('mpic_error:coordinator:cohort', 'The coordinator could not construct a cohort of size {0}') | ||
| COHORT_SELECTION_ERROR = ('mpic_error:coordinator:cohort_selection', 'The coordinator could not select cohort number {0} from available cohorts.') |
There was a problem hiding this comment.
I'm not going to block on this, but somehow my C programing mindset gets a little scared when I see numbered format tokens in string literals particularly when the format string is declared separately from the format commend. I think this is all good but if one of these strings was rewritten to have fewer or more format tokens, would that cause an error (at least its not going to just buffer overflow like it would in C).
There was a problem hiding this comment.
It won't cause issues like in C and thankfully there's unit tests that exercise the error code but it's not as elegant as maybe some other approach could be.
Anthropic Claude's take:
Key difference from C: Unlike C's format string vulnerabilities, Python's string formatting is type-safe and memory-safe. There's no buffer overflow risk, and mismatches produce clear runtime errors rather than undefined behavior or security issues.
Practical considerations:
- The error would be caught immediately when that code path executes (unlike silent C corruption)
- Unit tests covering these error cases would catch mismatches
- f-strings (f"Response status {status}") would make this mismatch impossible since variables are directly embedded, though they'd require the values at definition time rather than later formatting
The pattern here (constants with deferred formatting) is reasonable for error definitions. The main risk is maintenance errors that tests should catch.
This pull request introduces several enhancements and bug fixes across the codebase, most notably improving domain name handling in
DomainEncoder, adding support for selecting a specific cohort for single-attempt MPIC orchestration, and expanding related test coverage. It also includes some refactoring, such as relocating exceptions and updating error messages.Domain name handling improvements:
DomainEncoder.prepare_target_for_lookupto correctly detect and handle already punycode-encoded domains (including inner labels), ensuring they are not double-encoded and raising clear errors for malformed domains. Added stricter validation for wildcards and malformed input.DomainEncoderto cover more edge cases, including already-encoded domains, wildcards, inner punycode labels, and malformed domains. [1] [2]MPIC orchestration enhancements:
cohort_for_single_attemptparameter inMpicRequestOrchestrationParameters, allowing users to select a specific cohort for a single orchestration attempt. The coordinator now validates this parameter and raises a newCohortSelectionExceptionif the requested cohort is invalid. [1] [2] [3] [4] [5] [6] [7]Refactoring and error handling:
CohortCreationExceptiontompic_request_errors.pyand introduced a newCohortSelectionExceptionfor invalid cohort selection. Updated all imports and error messages accordingly. [1] [2] [3] [4] [5] [6] [7]6.2.0in__about__.py.Test improvements: