Has anyone run into the error "Cannot read property 'ranges' of null"?

Trying to debug my code, and I’ve run into this error several times. I never know what causes it.

"Cannot read property 'ranges' of null"

This is one example that has it… I just need to know maybe which function can cause that error? Like maybe DateTimeTruncate or something?

[Overall Times]
    .FormulaMap(
        RunActions(
            WithName(CurrentValue, CurrentOverallTimesRow,
            WithName(
                [Time Logs].Filter(Date = CurrentOverallTimesRow.Day and User = CurrentOverallTimesRow.User), 
                FilteredTimes,
                ModifyRows(
                    CurrentOverallTimesRow, [Logged Time],
                    ListCombine(
                        WithName(FilteredTimes.Filter(_isManualDuration = false).Sort(true, [Time Logs].[Start Time]),                     
                        TodaysTimes,
                        TodaysTimes
                            .FormulaMap( 
                                Concatenate(
                                    _Color(
                                        IF(CurrentValue.[Start Time].ToTime() > CurrentOverallTimesRow.[End Time] OR CurrentValue.[End Time].ToTime() < CurrentOverallTimesRow.[Start Time], "#ff0000", "#000000"),     
                                        Concatenate(
                                            "(", Duration(CurrentValue.Duration.DateTimeTruncate("minutes")).ToText(), ") ",                         
                                            CurrentValue.Period
                                        )
                                    ) , 
                                    IF(
                                        CurrentValue.[End Time] != [Next Log Start] AND (NOT(TodaysTimes.[End Time].Max() = CurrentValue.[End Time]) OR CurrentOverallTimesRow.Day = today()), 
                                        Concatenate(" (" , Duration(Duration(IfBlank(CurrentValue.[Next Log Start], Now()) - CurrentValue.[End Time]).DateTimeTruncate("Minutes")).ToText() , ")"
                                        ), 
                                        ""
                                    ) 
                            ))),

                            WIthName(
                                FilteredTimes.Filter(_isManualDuration = true).Duration, ManualEntries, 
                                IF(IsNotBlank(ManualEntries), List("Manual Entry(s): ", ManualEntries), "-")
                            )
                    ).BulletedList()

                )
            )
            )
        )
    )

Hello @N_G ,

It is kind of hard to debug your code, but I would guess that the error means you are trying to use a property (like .Day) from an object that doesn’t have properties (like CurrentOverallTimesRow).

Looking at your code I think you are not using WithName the way it is intended to be used. Start with simple bits of code, make sure they work and add one piece at at time, or combine working formulas in extra columns - that way you will find out where and when it stops working or starts to generate errors.

Perhaps I am completely wrong, but this is my first thing that comes to mind.

Thanks @joost_mineur,

I know I gave limited information, so your thoughts are helpful! I will start checking the properties and pulling this out into several columns to debug.

How to you mean “not how it was intended”? If I’m shooting myself in the foot it would be good to know XD

I have seen it used as TableName.Filter(Withname(CurrentValue, CurrentTableNameRow, CurrentTableNameRow.Filter(CurrentValue.Name = “Test”))). Is this what you would call intended method, to just rename CurrentValue so it can be used down stream?

I have been starting to use WithName in order to essentially split out a part of the code that is repeated without creating a separate row. Do you think this is a problem?

Hmm… so i just went back to my doc to start debugging and the error no longer exists. This is in a time tracking doc, and I spent some time cleaning up some of the entries (End greater than Start, Times overlapping, etc). I wonder if that’s what fixed it… as I don’t know what would have a property of “range” and maybe a date or duration makes sense.

Hello @N_G ,
Nesting WithName works. The purpose of WithName is to reuse a complex formula by giving it a name (that makes sense to you) and not having to retype the complex formula if it has to be used a couple of times within your larger formula.

The way I see it used in your sample in your answer to me is that you give CurrentValue a new name (CurrentTableNameRow), which is not really making it easier than keep on using Current Value.

Consider this formula:
Today().Year() - thisRow.DOB.Year() - If(Date(Today().Year(), thisRow.DOB.Month(), thisRow.DOB.Day()) > Today(), 1, 0) and imagine you have to reuse this formula a couple of times in your larger formula - it would be hard to read and to edit/debug.

When using WithName, you only have to write the formula once (giving you one place to edit/debug) and you can reuse it as often as you want - like this:
WithName( If(Date(Today().Year(), thisRow.DOB.Month(),thisRow.DOB .Day()) > Today(), 1, 0), YearFix, Concatenate( Year(Today())-year(thisRow.DOB)-YearFix, " years and ", ToNumber( today()-ToDate(Year(Today())-YearFix+ "/"+month(thisRow.DOB)+ "/"+Day(thisRow.DOB))), " day(s)"))
The formula has been renamed YearFix and is used twice in the rest of the formula.

You can see this in a working example on my sample page:

An extra column with a nested example is added, not really useful in this case, but just for the purpose of illustrating that it works.

Greetings,
Joost

Thanks @joost_mineur! I love learning more about how to use coda.

I do have a question about the Current Value rename that I do. So the reason I do it is because sometimes I have a Filter inside a Filter, and if I want to use the CurrentValue of filter one, I can’t, as I think it grabs the CurrentValue of the nearest filter. I never rename CurrentValue without there being a mashup of CurrentValues later on.

For Instance in the snippet from my post below. the bolded (6th line, with two stars around it) CurrentOverallTimesRow could be written as CurrentValue if I didn’t WithName it into its new name, but then wouldn’t the computer think I meant the CurrentValue of the [Time Logs] table? since the filter there is Date = CurrentOverallTimesRow.Day (which is technically CurrentValue.Date = CurrentValue.Day) but they aren’t both talking about hte same CurrentValue… one is for the OverallTimes table and one is for the Time Logs table.

[Overall Times]
    .FormulaMap(
        RunActions(
            WithName(CurrentValue, CurrentOverallTimesRow,
            WithName(
                [Time Logs].Filter(Date = **CurrentOverallTimesRow**.Day and User = CurrentOverallTimesRow.User), 
                FilteredTimes,

Hello @N_G ,

I understand what you are saying, but I can’t answer your question. What you say makes sense, but there is only one way to find out for sure and that is working with a relatively small dataset and testing. I am not sure if currentvalue changes within your function - and I am not sure if it really matters. If you need help you best make a small doc to share, copy representative tables to the shared doc and ask the community if you need help.
You are trying to use WithName to store variables and I think it is not meant for that purpose, but that doesn’t mean it won’t work.
Greetings,
Joost

Hi @N_G , @joost_mineur ,
purpose of WithName() has been primarily exactly what @N_G mentioned (and she is right): to avoid overriding of nested CurrentValue(s).

Incidentally, it’s also useful to avoid code replication and to better manage variables meaning.
So, it’s also a matter of personal style :wink:

1 Like

Hey Federico,
Thank you for pointing this out: I reread the intro mail about the WithName introduction and I am embarrassed to have to admit I overlooked the 2nd half of the introduction posting. It seems pretty obvious now, I am certain I will be using this quite a lot.
Greetings,
Joost

1 Like

Thank you @joost_mineur and @Federico_Stefanato, I appreciate the discussion as it is helping me become more comfortable with Coda.

1 Like

Ran into the error “Cannot read property ‘ranges’ of null” and just wanted to document every time this error comes up just in case it will help others down the line.

Situation: Deleted Row Reference

Tables w/ Columns:

  • [Tasks]:
    • Task.Name,
  • [TimeLogs]:
    • TimeLogs.Task,
    • TimeLogs.Start Time,
    • TimeLogs.End Time,
    • TimeLogs.Date,
  • [Daily Summary]:
    • DailySummary.Day,
    • DailySummary.TimeLogsForDay (=TimeLogs.Filter(Date = Day)),
    • DailySummary.TimeLogsBulletedList (=thisRow.[TimeLogsForDay ].Task.BulletedLIst()

Description: Daily Summary looks for all TimeLogs that occurred on X date. TimeLogs has a lookup to a row in Tasks. The TimeLog was not deleted so is showing up in DailySummary. When I try to reference the Task Name in DailySummary using TimeLogs, it fails with “Cannot read property ‘ranges’ of null” since TimeLog is referencing a Task that was accidently deleted. Error only showed up in TimeLogsBulletedList as TimeLogsForDay showed the Task (but grayed out to show it no longer existed).

Solution: Restore deleted row

1 Like

Thanks for sharing.
Did the process halt upon running into this error or did it continue with the rest of the non-failing records?
Greetings,
Joost

The process was not halted for the columns in the remaining rows. This error might halt the process if it was not a column row by row calculation.

I would just have a little red flag like below in any row in that column that failed.
So the below image has three rows, the first one referenced a deleted Task and therefore had the error and red triangle flag, the second row had Tasks and they display correctly, the third row had no tasks so is correctly empty.

OK - that is actually a pretty nice result - in particular the little red flag indicating a problem.
It takes a little getting used to - I have plenty of programming experience but every so often I run into things (like using a table.column name, or only the table, or only the column), that don’t work exactly as I had expected, but I find it a lot easier to work with and solve problems than just about any other (non)coding environment.
Gr. Joost