ajaxorg/ace · error · Error

invalid fold style:

Error message

invalid fold style: 

What it means

setFoldStyle() validates the style against $foldStyles (currently 'manual' and 'markbegin'/'markbeginend' set). Passing any other string throws, listing the valid options in the message.

Source

Thrown at src/edit_session/folding.js:835

                return false;
            }
        });
    };
    
    // structured folding
    this.$foldStyles = {
        "manual": 1,
        "markbegin": 1,
        "markbeginend": 1
    };
    this.$foldStyle = "markbegin";
    
    /**
     * @param {string} style
     */
    this.setFoldStyle = function(style) {
        if (!this.$foldStyles[style])
            throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
        
        if (this.$foldStyle == style)
            return;

        this.$foldStyle = style;
        
        if (style == "manual")
            this.unfold();
        
        // reset folding
        var mode = this.$foldMode;
        this.$setFolding(null);
        this.$setFolding(mode);
    };

    /**
     * @param {import("../../ace-internal").Ace.FoldMode} foldMode
     */

View on GitHub (pinned to 2c1eddc392)

Solutions

  1. Use one of the valid styles: 'manual', 'markbegin', or 'markbeginend'
  2. Check the error message listing allowed keys
  3. Fix casing — names are lowercase

Example fix

// before
session.setFoldStyle('markers');
// after
session.setFoldStyle('markbegin');
Defensive patterns

Strategy: validation

Validate before calling

var FOLD_STYLES = ['manual', 'markbegin', 'markbeginend'];
if (!FOLD_STYLES.includes(style)) throw new Error('bad fold style: ' + style);
session.setFoldStyle(style);

Type guard

function isValidFoldStyle(s) { return s === 'manual' || s === 'markbegin' || s === 'markbeginend'; }

Try / catch

try { session.setFoldStyle(style); } catch (e) { if (/invalid fold style/.test(e.message)) session.setFoldStyle('markbegin'); else throw e; }

Prevention

When it happens

Trigger: Calling session.setFoldStyle('clickable') or any misspelled/unrecognized style name.

Common situations: Copying fold style names from other editors (CodeMirror, vim); guessing style names; typos like 'markBegin' with wrong casing.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of ajaxorg/ace@2c1eddc392 (2026-08-30). Data as JSON: /api/errors/b231121864e9ab8f. Report an issue: GitHub.