Skip to content

Handle null values in Interpolated strings #228

@Nakano37

Description

@Nakano37

MagicalBox.cs:78 throws if you have a null value in an interpolated string variable:

    public bool TryReadTo(Type type, int offset, int alignment, string? format, ref Utf8StringWriter<IBufferWriter<byte>> handler)
    {
        if (offset < 0) return false;
        if (type.IsEnum) goto USE_READER;

If you instead this is changed to:

    public bool TryReadTo(Type? type, int offset, int alignment, string? format, ref Utf8StringWriter<IBufferWriter<byte>> handler)
    {
        if (offset < 0) return false;
        if (type == null) return false;
        if (type.IsEnum) goto USE_READER;

this it handles it correctly without any further changes. The exception thrown by it causes very hard to track down errors in the log file and the InternalErrorLogger just shows:

[Warning] [2026-03-06 14:09:42.400] [15] - Internal Logging exception: Object reference not set to an instance of an object. :    at ZLogger.Internal.MagicalBox.TryReadTo(Type type, Int32 offset, Int32 alignment, String format, Utf8StringWriter1& handler)
   at ZLogger.MessageSequence.ToString(IBufferWriter1 writer, MagicalBox box, Span1 parameters)
   at ZLogger.Formatters.PlainTextZLoggerFormatter.FormatLogEntry(IBufferWriter1 writer, IZLoggerEntry entry)

Which doesn't make the actual problem log line any easier to find.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions