Code review comment: Can you please elaborate on why you think it shouldn't be an error?

Code under review:
boolean validateErrorVariable(BLangErrorVariable errorVariable, SymbolEnv env) {
        BType varType = Types.getReferredType(errorVariable.getBType());
        BErrorType errorType;
        switch (varType.tag) {
            case TypeTags.UNION:
                BUnionType unionType = ((BUnionType) varType);
                List<BErrorType> possibleTypes = types.getAllTypes(unionType, true).stream()
                        .filter(type -> TypeTags.ERROR == type.tag)
                        .map(BErrorType.class::cast)
                        .collect(Collectors.toList());

                if (possibleTypes.isEmpty()) {
                    dlog.error(errorVariable.pos, DiagnosticErrorCode.INVALID_ERROR_BINDING_PATTERN, varType);
                    return false;
                }

                if (possibleTypes.size() > 1) {
                    LinkedHashSet<BType> detailType = new LinkedHashSet<>();
                    for (BErrorType possibleErrType : possibleTypes) {
                        detailType.add(possibleErrType.detailType);
                    }
                    BType errorDetailType = detailType.size() > 1
                            ? BUnionType.create(null, detailType)
                            : detailType.iterator().next();
                    errorType = new BErrorType(null, errorDetailType);
                } else {
                    errorType = possibleTypes.get(0);
                }
                break;
            case TypeTags.ERROR:
                errorType = (BErrorType) varType;
                break;
            case TypeTags.SEMANTIC_ERROR:
                
                return false;
            default:
                dlog.error(errorVariable.pos, DiagnosticErrorCode.INVALID_ERROR_BINDING_PATTERN,
                        varType);
                return false;
        }
        errorVariable.setBType(errorType);

        if (!errorVariable.isInMatchStmt) {
            BLangSimpleVariable errorMsg = errorVariable.message;
            if (errorMsg != null) {
                defineMemberNode(errorVariable.message, env, symTable.stringType);
            }

            BLangVariable errorCause = errorVariable.cause;
            if (errorCause != null) {
                if (errorCause.getKind() == NodeKind.VARIABLE &&
                        names.fromIdNode(((BLangSimpleVariable) errorCause).name) == Names.IGNORE) {
                    dlog.error(errorCause.pos,
                            DiagnosticErrorCode.CANNOT_USE_WILDCARD_BINDING_PATTERN_FOR_ERROR_CAUSE);
                    return false;
                }
                defineMemberNode(errorVariable.cause, env, symTable.errorOrNilType);
            }
        }

        if (errorVariable.detail == null || (errorVariable.detail.isEmpty()
                && !isRestDetailBindingAvailable(errorVariable))) {
            return validateErrorMessageMatchPatternSyntax(errorVariable, env);
        }

        BType detailType = Types.getReferredType(errorType.detailType);
        if (detailType.getKind() == TypeKind.RECORD || detailType.getKind() == TypeKind.MAP) {
            return validateErrorVariable(errorVariable, errorType, env);
        } else if (detailType.getKind() == TypeKind.UNION) {
            BErrorTypeSymbol errorTypeSymbol = new BErrorTypeSymbol(SymTag.ERROR, Flags.PUBLIC, Names.ERROR,
                    env.enclPkg.packageID, symTable.errorType,
                    env.scope.owner, errorVariable.pos, SOURCE);
            
            errorVariable.setBType(new BErrorType(errorTypeSymbol, symTable.detailType));
            return validateErrorVariable(errorVariable, env);
        }

        if (isRestDetailBindingAvailable(errorVariable)) {
            defineMemberNode(errorVariable.restDetail, env, symTable.detailType);
        }
        return true;
    }

Line commented on: DiagnosticErrorCode.CANNOT_USE_WILDCARD_BINDING_PATTERN_FOR_ERROR_CAUSE);

Revised code:
boolean validateErrorVariable(BLangErrorVariable errorVariable, SymbolEnv env) {
        BType varType = Types.getReferredType(errorVariable.getBType());
        BErrorType errorType;
        switch (varType.tag) {
            case TypeTags.UNION:
                BUnionType unionType = ((BUnionType) varType);
                List<BErrorType> possibleTypes = types.getAllTypes(unionType, true).stream()
                        .filter(type -> TypeTags.ERROR == type.tag)
                        .map(BErrorType.class::cast)
                        .collect(Collectors.toList());

                if (possibleTypes.isEmpty()) {
                    dlog.error(errorVariable.pos, DiagnosticErrorCode.INVALID_ERROR_BINDING_PATTERN, varType);
                    return false;
                }

                if (possibleTypes.size() > 1) {
                    LinkedHashSet<BType> detailType = new LinkedHashSet<>();
                    for (BErrorType possibleErrType : possibleTypes) {
                        detailType.add(possibleErrType.detailType);
                    }
                    BType errorDetailType = detailType.size() > 1
                            ? BUnionType.create(null, detailType)
                            : detailType.iterator().next();
                    errorType = new BErrorType(null, errorDetailType);
                } else {
                    errorType = possibleTypes.get(0);
                }
                break;
            case TypeTags.ERROR:
                errorType = (BErrorType) varType;
                break;
            case TypeTags.SEMANTIC_ERROR:
                
                return false;
            default:
                dlog.error(errorVariable.pos, DiagnosticErrorCode.INVALID_ERROR_BINDING_PATTERN,
                        varType);
                return false;
        }
        errorVariable.setBType(errorType);

        if (!errorVariable.isInMatchStmt) {
            BLangSimpleVariable errorMsg = errorVariable.message;
            if (errorMsg != null) {
                defineMemberNode(errorVariable.message, env, symTable.stringType);
            }

            BLangVariable errorCause = errorVariable.cause;
            if (errorCause != null) {
                if (errorCause.getKind() == NodeKind.VARIABLE &&
                        names.fromIdNode(((BLangSimpleVariable) errorCause).name) == Names.IGNORE) {
                    dlog.error(errorCause.pos,
                            DiagnosticErrorCode.CANNOT_USE_WILDCARD_BINDING_PATTERN_FOR_ERROR_CAUSE);
                    return false;
                }
                defineMemberNode(errorCause, env, symTable.errorOrNilType);
            }
        }

        if (errorVariable.detail == null || (errorVariable.detail.isEmpty()
                && !isRestDetailBindingAvailable(errorVariable))) {
            return validateErrorMessageMatchPatternSyntax(errorVariable, env);
        }

        BType detailType = Types.getReferredType(errorType.detailType);
        if (detailType.getKind() == TypeKind.RECORD || detailType.getKind() == TypeKind.MAP) {
            return validateErrorVariable(errorVariable, errorType, env);
        } else if (detailType.getKind() == TypeKind.UNION) {
            BErrorTypeSymbol errorTypeSymbol = new BErrorTypeSymbol(SymTag.ERROR, Flags.PUBLIC, Names.ERROR,
                    env.enclPkg.packageID, symTable.errorType,
                    env.scope.owner, errorVariable.pos, SOURCE);
            
            errorVariable.setBType(new BErrorType(errorTypeSymbol, symTable.detailType));
            return validateErrorVariable(errorVariable, env);
        }

        if (isRestDetailBindingAvailable(errorVariable)) {
            defineMemberNode(errorVariable.restDetail, env, symTable.detailType);
        }
        return true;
    }