Skip to content

Edge Cases and Errors

m4bwav edited this page Sep 30, 2026 · 2 revisions

Two kinds of trouble behave differently. A wrong argument throws a TypeError at once, before any request. Anything that goes wrong with a page (it fails, is slow, is not HTML, cannot be reached) is silent: the link stays as it was written and the call succeeds. This page lists both.

A link was left unchanged

The call never says why. The reasons, each seen in a run for this wiki:

Reason Where it is shown
It is not a plain link: a markdown link or image, an autolink, a reference definition, an HTML attribute, code, no scheme, another scheme, a user name or password, a single-label host How links are replaced
The address is followed by a double quote, so it reads as an attribute value How links are replaced
Its path ends in an image extension, or the page's Content-Type is an image How links are replaced
The page answered with an error status, is not HTML, or has no title the same section
The page took longer than timeout (10 seconds by default) API reference, Commands
No request could be made: Deno without --allow-net, or a proxy that Node does not use Getting started, Recipes
The certificate of an https page was not trusted below

When every link in a text is left, check the last two first: the text comes back whole, with no error, when the requests never leave the machine. On Node 24.18.0, an https page whose certificate the runtime does not trust also left its link silently, while an http link in the same text was replaced.

A page that never answers

With the default timeout, a page that accepts the connection and never answers is given up after 10 seconds for the image check and again for the title. The golden replay's never-answering case came back unchanged within its 25-second wait, where 1.1.16 never called back at all (Versions and upgrading).

For a hard limit on the whole call, pass a signal (Recipes).

Aborting

An aborted signal is the only thing that makes the Promise form reject, and it rejects even for a text without links. The callback form gets the markdown unchanged instead. The messages are in the API reference.

Wrong arguments

Every TypeError and its message is listed in the API reference. In short: markdown must be a string or falsy; the second argument must be a function, an options object, null or undefined; template must be a string using only variables, sections, inverted sections and comments; timeout must be a positive number; signal must be an AbortSignal. The options are checked even when the markdown is empty.

Two traps that throw:

  • A number where the template goes, in the callback form: replacePlainLinks(text, callback, 42) throws template must be a string, not 42. 1.1.16 deleted the link instead.
  • A string as the second argument: replacePlainLinks('x', 'yes') throws the second argument must be a callback or an options object, not "yes". Pass options as an object, or the template third.

The command line

The command exits 0 whenever it printed the markdown, whatever happened to the links, and exits 1 for a bad option, a missing file or a bad template. The messages are on Commands.

Text that is not a link

Everything outside the replaced links is left exactly as written: HTML entities such as & stay as they are, line endings are kept (CRLF included, from the golden replay), and a very long text with one link is handled like a short one (a 200,000-character case in the golden replay). 1.1.16 decoded entities across the whole text, which is one of the changes on Versions and upgrading.

Clone this wiki locally