Skip to content

fix: report the web view and CSS failures that were never surfaced - #84

Merged
NuPlay merged 1 commit into
mainfrom
fix/report-webview-and-css-errors
Aug 29, 2026
Merged

fix: report the web view and CSS failures that were never surfaced#84
NuPlay merged 1 commit into
mainfrom
fix/report-webview-and-css-errors

Conversation

@NuPlay

@NuPlay NuPlay commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Problem

RichTextError.webViewConfigurationFailed and .cssGenerationFailed are public API, are described by errorDescription, and the README tells callers to handle them - but nothing in the package ever constructed them. The only errors that could actually reach an .onError handler were htmlLoadingFailed and mediaHandlingFailed.

Deleting two cases the documentation actively teaches would break every consumer that switches over RichTextError exhaustively. Giving them the real failure modes they were missing is better.

Changes

webViewConfigurationFailed now fires on macOS when drawsBackground cannot be set:

webview.setValue(false, forKey: "drawsBackground")

That reaches WKWebView through KVC on a key that is not public API. setValue(_:forKey:) raises NSUnknownKeyException if the key ever goes away, and that is an Objective-C exception Swift cannot catch, so it would take the host app down. The setter is probed with responds(to:) first and the failure is reported instead of trapping.

cssGenerationFailed now fires when fontColor or linkColor holds an invalid hex value. Nothing rejected those: they reached the stylesheet as color: #whatever, the browser dropped the declaration along with the rest of the rule, and the colour silently fell back to the default with no way to trace it from the outside.

ColorSet.isValid was the natural hook for that check - and it was itself dead, public API referenced only by its own tests. Its length rule was wrong while nobody used it:

  • #RGB and #RGBA are valid CSS but were reported invalid
  • it disagreed with BackgroundColor.isHexColorLiteral, which already accepted all four lengths

Both now accept 3, 4, 6 and 8, and the check no longer builds an NSPredicate per call.

Compatibility

No public API removed. Existing .onError handlers keep compiling and simply start receiving two error cases that previously could not occur.

Checked for false positives: the four default colours are 6-digit hex, the UIColor/NSColor initialisers always produce 6 or 8 digits via .hex, and the sample app uses 6-digit values, so nothing in the default configuration trips the new validation.

`RichTextError.webViewConfigurationFailed` and `.cssGenerationFailed` are public
API, documented in the README, and nothing in the package ever constructed them.
Give them the real failure modes they were missing.

`webViewConfigurationFailed` now fires on macOS when `drawsBackground` cannot be
set. That call reaches WKWebView through KVC on a key that is not public API,
and `setValue(_:forKey:)` raises NSUnknownKeyException if the key ever goes away
- an Objective-C exception Swift cannot catch, so it would take the host app
down. The setter is probed first and the failure is reported instead.

`cssGenerationFailed` now fires when `fontColor` or `linkColor` holds an invalid
hex value. Nothing rejected those: they reached the stylesheet as
`color: #whatever`, the browser dropped the declaration, and the colour silently
fell back to the default with no way to trace it.

That second hook also puts `ColorSet.isValid` to work, which until now was
public API referenced only by its own tests. Its length rule was wrong while it
was unused: `#RGB` and `#RGBA` are valid CSS but were reported invalid, and it
disagreed with `BackgroundColor.isHexColorLiteral`, which already accepted all
four lengths. Both now accept 3, 4, 6 and 8, and the check no longer builds an
NSPredicate per call.
Copilot AI lite review requested due to automatic review settings August 29, 2026 09:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@NuPlay NuPlay added the bug Something isn't working label Aug 29, 2026
@NuPlay NuPlay self-assigned this Aug 29, 2026
@NuPlay
NuPlay merged commit 093b6f5 into main Aug 29, 2026
1 check passed
@NuPlay
NuPlay deleted the fix/report-webview-and-css-errors branch August 29, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants