egametang/ET · warning · Exception

text={3}, index={0}, chr='{1}':此处只能出现'{2}'

Error message

text={3}, index={0}, chr='{1}':此处只能出现'{2}'

What it means

StrUtil.GetStrChunk parses placeholder syntax like {key1} in template strings. Error case 0 fires in the Escape state when a closing brace '}' is followed by a character that is not the same as the preceding one — i.e. a malformed escape sequence. Only thrown when throwError=true.

Source

Thrown at Packages/cn.etetet.packagemanager/Editor/Tools/StrUtil_StrChunk.cs:174

                            sb.Append(c);
                        }
                        else
                        {
                            throwErrId = 0;
                            sb.Append(lastChar).Append(c);
                        }

                        state = ReadChunkState.ReadText;
                        break;
                }

                //处理错误
                if (throwError && throwErrId > -1)
                {
                    switch (throwErrId)
                    {
                        case 0:
                            throw new Exception(string.Format("text={3}, index={0}, chr='{1}':此处只能出现'{2}'", i, c,
                                                              lastChar, value));
                        case 1:
                            throw new Exception(string.Format("text={2}, index={0}, chr='{1}', 此处只能出现小写英文字符", i, c,
                                                              value));
                        case 2:
                            throw new Exception(string.Format("text={2}, index={0}, chr='{1}', 此处只能出现小写英文或1-9的数字", i, c,
                                                              value));
                        case 3:
                            throw new Exception(string.Format("text={2}, index={0}, chr='{1}', 0-9的数字或'}}'", i, c,
                                                              value));
                    }
                }

                lastChar = c;
            }

            //结尾处理
            if (state != ReadChunkState.ReadText)

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Fix the template: escape a literal '}' as '}}' and a literal '{' as '{{'.
  2. Re-run GetStrChunk with throwError=false to get fault-tolerant parsing and inspect where it diverges.
  3. Audit all template/localization strings for unbalanced or stray braces.

Example fix

// before — stray brace
var chunks = StrUtil.GetStrChunk("hello}world", throwError: true);

// after — escaped
var chunks = StrUtil.GetStrChunk("hello}}world", throwError: true);
Defensive patterns

Strategy: validation

Validate before calling

StrUtil.GetStrChunk(template, throwError: false); // tolerant first pass to detect issues

Try / catch

try { chunks = StrUtil.GetStrChunk(tpl, throwError: true); }
catch (Exception ex) { Log.Error($"bad template: {tpl}, {ex.Message}"); chunks = StrUtil.GetStrChunk(tpl, throwError: false); }

Prevention

When it happens

Trigger: A template string contains a lone '}' that is not part of a {key} placeholder and is not a valid escape ('}}' for a literal '}'). For example "text}x" triggers it because '}' enters Escape state and the next char differs.

Common situations: Localization/template strings with stray braces from manual editing; copy-pasting content that contains regex or code braces into a template field; format strings imported from external sources.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/3ac6c35f795d9627. Report an issue: GitHub.