Node HandbookNODE HANDBOOK
Configuration

Clash Verge Rev: yaml cannot unmarshal

This is a type error, not a syntax error. The YAML is well-formed and indentation is fine; a value simply has the wrong kind for the field it was written into. The message names both kinds, which is enough to find it.

Last updated: 2026-11-24 · Every error string on this page was reproduced on a real client.

Type error versus syntax error

YAML failures come in two families and they need different responses.

FamilyTypical messageWhat it means
Syntaxdid not find expected key, found character that cannot start any tokenThe document structure is malformed; the parser cannot build a tree
Typecannot unmarshal string into ..., cannot unmarshal !!str into boolThe tree is fine; one leaf has the wrong kind

Only the second family is this article. The parser got far enough to know field names, which means indentation and structure are correct. The problem is a single value.

Read the two types in the message

The message has a fixed shape: it names the type it found and the type the field requires.

yaml: unmarshal errors:
  line 42: cannot unmarshal !!str `true` into bool

Here the file supplied the string "true" — quoted — where the field is a boolean. Quoting is the entire cause. The parser reports !!str because a quoted scalar is a string even when it looks like a keyword.

Three shapes account for nearly every occurrence:

  1. A quoted boolean or number. allow-lan: "true", port: "7890". Unquote it. This is what template generators do when they interpolate values without type awareness.
  2. A scalar where a list belongs. A field expecting a list of names got a single name. Wrap it in brackets and it parses.
  3. A list where a mapping belongs. A field expecting an object with keys got a sequence. This is usually an indentation slip that moved a block one level, which is why it looks like a syntax problem and reports as a type problem.

The line number is trustworthy — use it

Unlike many parsers, the line reported here is the line with the offending value, not the start of the enclosing block. Open the file at that line and read the value, not the key.

sed -n '40,44p' config.yaml

Two things to check at that point:

  • Whether the value is quoted. If it is, and the field is boolean or numeric, remove the quotes. This is the single most common fix.
  • Whether the value belongs to that key at all. If the indentation of the block above drifted, the value may be attached to a key you did not intend, and the type mismatch is a symptom of the drift rather than of the value.

If the reported line is blank or a comment, the parser's line corresponds to where the value logically ended, so look upward for the last real value before it.

Fields that fail most often

Field shapeRequiresCommon mistake
allow-lan, ipv6, unified-delay, tcp-concurrentbooleanQuoted "true" from a template
port, mixed-port, socks-portintegerQuoted number, or a value with a trailing comment glued to it
dns.nameserver, dns.fallbacklist of stringsA single bare address instead of a list
proxies, proxy-groupslist of mappingsA mapping at the top level where a list was expected
ruleslist of stringsA nested list from a copy-paste
tun.stackstring from a fixed setA value from a different core's vocabulary

The last row is worth noting because it produces a different message — an invalid value rather than a type mismatch — and the two get confused. A type error is about kind; a value error is about membership.

Fix by shape, not by trial

The reliable procedure is: read the two types in the message, look at the line, and change only the kind. Do not reformat the file, do not re-indent neighbouring blocks, and do not re-import the profile — a re-import restores the same generated value and the same error.

If the file is generated rather than hand-written, the fix belongs in the generator. Editing the output works until the next generation cycle overwrites it, at which point the error returns with no memory that it was fixed. This is the case for profiles produced by a conversion service, where the quotes are added by the template rather than typed by anyone.

One more check before saving: if the file came from a Windows editor, confirm it does not carry a byte-order mark and uses consistent line endings. A BOM at the start produces a syntax error rather than a type error, but the two appear together often enough that it is worth ruling out in one look.

Frequently asked

Does this mean my YAML is malformed?

No. A malformed document produces a syntax error about tokens or expected keys. This message means the structure parsed and one value has the wrong kind, so the fix is a single Leaf rather than the layout.

Why does a quoted true fail?

Because quotes make it a string. The field is a boolean, and the parser does not coerce strings into booleans. Remove the quotes and the same text becomes the keyword it looks like.

The line number points at a comment. Why?

The parser reports where the value ended, which can be after a trailing comment or a blank line. Look upward for the last real value in the same block.

Can I just delete the offending key?

Sometimes. Removing an optional key makes the core use its default, which may be exactly what you want. Removing a required key moves the failure rather than fixing it, and the next message will name a missing field instead.

It is a subscription profile. Why can I not fix it?

Because the profile is regenerated from the provider, so any edit is lost on the next update. Fix the generator or the conversion step, or copy the profile into a local file you maintain yourself and stop the automatic replacement.