Error in the_dims[[2]] : subscript out of bounds

I often use the Rethinking package as an interface to RStan. Here is the model I’m working on now, in rethinking:

sleep1 ← ulam(
alist(

# Dark phase
nNREMS_Dark ~ dgampois(mu_nNREMS_Dark, scale_nNREMS_Dark),
dNREMS_Dark ~ dgamma2(mu_dNREMS_Dark, scale_dNREMS_Dark),
nREMS_Dark ~ dgampois(mu_nREMS_Dark, scale_nREMS_Dark),
dREMS_Dark ~ dgamma2(mu_dREMS_Dark, scale_dREMS_Dark),
SWA_Dark ~ dgamma2(mu_SWA_Dark, scale_SWA_Dark),

    ## Multivariate prior for means of dark-phase measures
    c(log(mu_nNREMS_Dark), 
      log(mu_dNREMS_Dark), 
      log(mu_nREMS_Dark),
      log(mu_dREMS_Dark),
      log(mu_SWA_Dark)) ~ multi_normal(c(nu_nNREMS_Dark,
                                         nu_dNREMS_Dark,
                                         nu_nREMS_Dark,
                                         nu_dREMS_Dark,
                                         nu_SWA_Dark), 
                                       Rho_Sleep_Dark, 
                                       Sigma_Sleep_Dark),
        Rho_Sleep_Dark ~ lkj_corr(1),
        Sigma_Sleep_Dark ~ dexp(1),
    
        ### Linear models 
            # (Independent Animal intercepts may confound CCL; 
            # in which case, need to replace a_LPSxCCL priors with a_Sleep priors)
        nu_nNREMS_Dark <- a_nNREMS_Dark[Animal] + a_LPSxCCL_nNREMS_Dark[LPSxCCL],
        nu_dNREMS_Dark <- a_dNREMS_Dark[Animal] + a_LPSxCCL_dNREMS_Dark[LPSxCCL],
        nu_nREMS_Dark <- a_nREMS_Dark[Animal] + a_LPSxCCL_nREMS_Dark[LPSxCCL],
        nu_dREMS_Dark <- a_dREMS_Dark[Animal] + a_LPSxCCL_dREMS_Dark[LPSxCCL],
        nu_SWA_Dark <- a_SWA_Dark[Animal] + a_LPSxCCL_SWA_Dark[LPSxCCL],
        
            #### Priors for linear models
            a_nNREMS_Dark[Animal] ~ dnorm(log(48), 0.5), # based on idea that 1/3 spent in NREMS
            a_dNREMS_Dark[Animal] ~ dnorm(log(300), 0.5), # w/avg dNREMS ~ 5 min
            a_nREMS_Dark[Animal] ~ dnorm(log(48), 0.5), # based on idea that 1/10 spent in REMS
            a_dREMS_Dark[Animal] ~ dnorm(log(90), 0.5), # w/avg dREMS ~ 1.5 min
            a_SWA_Dark[Animal] ~ dnorm(log(100000), 0.5),
            
            c(a_LPSxCCL_nNREMS_Dark[LPSxCCL],
              a_LPSxCCL_dNREMS_Dark[LPSxCCL],
              a_LPSxCCL_nREMS_Dark[LPSxCCL],
              a_LPSxCCL_dREMS_Dark[LPSxCCL],
              a_LPSxCCL_dREMS_Dark[LPSxCCL]) ~ dnorm(0.0, 0.5),
        
    ## Priors for scale parameters
    c(scale_nNREMS_Dark,
      scale_dNREMS_Dark,
      scale_nREMS_Dark,
      scale_dREMS_Dark,
      scale_SWA_Dark) ~ dexp(1)

), data=sleep.dlist, chains=4, cores=4, iter=1000
)

In this model, and otherwise commonly, I get the following error

Error in the_dims[[2]] : subscript out of bounds

This is frustrating because I have no indication where the error occurs. My question is, is this a warning from Stan or from R? Is there a remedy or way to diagnose efficiently?

Many thanks

This will be something to do with the rethinking package, your best bet will be to open an issue on the package github here: GitHub - rmcelreath/rethinking: Statistical Rethinking course and book package