2.5.5 logs "Resource with id <id> not found in context <calling context>" on valid cross-context links #13278

Open
Mark-H opened this Issue Feb 8, 2017 · 10 comments

Projects

None yet

6 participants

@Mark-H
Collaborator
Mark-H commented Feb 8, 2017 edited

Summary

The 2.5.5 introduced a much appreciated log for bad links (#13268), but it's a bit too enthusiastic. Links to a resource within another context are logging an error even though they are valid.

Step to reproduce

Create a 2nd context, and add a resource in it. Link from web to the resource in that context with the [[~123]] link tag.

Observed behavior

Error messages in the log. For example three header links pointing to resources in another context:

[2017-02-08 16:46:39] (ERROR in modContext::makeUrl @ resource 605) Resource with id 322 was not found in context web
[2017-02-08 16:46:39] (ERROR in modContext::makeUrl @ resource 605) Resource with id 101 was not found in context web
[2017-02-08 16:46:39] (ERROR in modContext::makeUrl @ resource 605) Resource with id 493 was not found in context web
[2017-02-08 16:50:48] (ERROR in modContext::makeUrl @ resource 169) Resource with id 322 was not found in context web
[2017-02-08 16:50:48] (ERROR in modContext::makeUrl @ resource 169) Resource with id 101 was not found in context web
[2017-02-08 16:50:48] (ERROR in modContext::makeUrl @ resource 169) Resource with id 493 was not found in context web

Links are valid and functional.

Actually broken links are logged as such:

[2017-02-08 16:50:48] (ERROR in modContext::makeUrl @ resource 169) Resource with id 111 was not found in context web
[2017-02-08 16:50:48] (ERROR in resource 169 @ /path/to/core/model/modx/modparser.class.php : 1353) Bad link tag `[[~111]]` encountered

which makes me believe that we could drop the error triggered in makeUrl. Alternatively, the check in modContext->makeUrl should be moved to modX->makeUrl until after it automatically discovers the context that is being linked to, but Jason mentioned that was troublesome.

Expected behavior

No error log entry for valid cross-context links.

Environment

MODX Revolution 2.5.5. Not server specific other than the requirement for multiple contexts.

@sottwell
Contributor

Yes, the 'bad links' error is nice, but the 'not in context' error is just a nuisance.

@sottwell
Contributor

Maybe make it an info or a debug instead of an error?

@gravino81
gravino81 commented Feb 20, 2017 edited

I also encountered the same problem
[2017-02-20 17:10:16] (ERROR in modContext::makeUrl @ resource 238) Resource with id 98 was not found in context es
[2017-02-20 17:10:41] (ERROR in modContext::makeUrl @ resource 168) Resource with id 472 was not found in context web
the strange thing is that, I do not have a link from a resource point to other.

And I also found another problem with tagger

[2017-02-20 17:10:42] (ERROR in resource 186 @ ../core/model/modx/modparser.class.php : 1353) Bad link tag[[~]]encountered

In this case i have "Freeze URI" set for the resource to point the category, links are valid and functional.

@mrhaw
mrhaw commented Feb 20, 2017

Is this what changed #13268

@morgycatt
morgycatt commented Feb 21, 2017 edited

I've got the same problem on a multi language website using Babel. Each language has a separate context, and there are many pages in one language linking to another.
Every time a page template/chunk tries to create a URL with [[~id]] where the id is in a different context it throws an error.
(ERROR in modContext::makeUrl @ resource X) Resource with id Y was not found in context fr

This is everywhere across the website, so I think my only option is to comment lines out in the core code.
model\modx\modcontent.class.php
Lines 314 to 323
} else { /* $this->xpdo->log( xPDO::LOG_LEVEL_ERROR, "Resource with id {$id} was not found in context {$this->key}", '', __METHOD__, $this->xpdo->resource ? "resource {$this->xpdo->resource->id}" : __FILE__, $this->xpdo->resource ? '' : __LINE__ ); */ }

Is this a sensible solution?
I'm not so sure, but it's stopping the error log getting Huuuuuge :-)

@sottwell
Contributor
sottwell commented Feb 21, 2017 edited

I just changed it from LOG_LEVEL_ERROR to LOG_LEVEL_WARN
That way if you change the log_level in System Settings you'll get the warning message, but with the default setting you won't. Maybe LOG_LEVEL_INFO would be even more appropriate.

@Jako
Collaborator
Jako commented Feb 21, 2017 edited

I agree with Mark, that it could be enough to log only this error:

[2017-02-08 16:50:48] (ERROR in resource 169 @ /path/to/core/model/modx/modparser.class.php : 1353) Bad link tag `[[~111]]` encountered

So the patch in #13268 should be changed, that only that error will be logged (remove the logging enhancement in modcontext.class.php).

But since calling makeUrl with a wrong ID could not happen only in the MODX parser, I propose an enhancement: If it is possible to check (with a not expensive method) that the resource exists in another context, this should be preferred. And at least, if thats not possible: the MODX debug level setting could trigger an expensive database resource check.

@sottwell
Contributor

I'm inclined to think that this message could be useful under certain conditions, so maybe just changing it to an INFO or even a DEBUG level would stop if from being a nuisance, while leaving it available.

@sottwell
Contributor

Somebody went to a lot of trouble to code this, I'd hate to just throw it out when a simple change of the log level would solve the problem.

@Mark-H Mark-H added a commit to Mark-H/revolution that referenced this issue Feb 21, 2017
@Mark-H Mark-H Lower log level for 'resource with id not found in context' to info [#โ€ฆ 6991df5
@Mark-H
Collaborator
Mark-H commented Feb 21, 2017

Pull request created #13305 to lower the log level to INFO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment