Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BridgeException: Cannot find the referenced element #80

Closed
ghost opened this issue Jun 13, 2023 · 1 comment · Fixed by #81
Closed

BridgeException: Cannot find the referenced element #80

ghost opened this issue Jun 13, 2023 · 1 comment · Fixed by #81
Assignees
Labels
spec compliance Some behavior may not be spec-compliant
Milestone

Comments

@ghost
Copy link

ghost commented Jun 13, 2023

Replicate

  1. Create an SVG file with an unused reference. This can happen by editing an SVG created in Adobe Illustrator with Inkscape and removing objects. See e.svg.txt. Essentially:

    <clipPath
      id="SVGID_00000145770309263158979710000005844928936766913719_">
    <use
      xlink:href="#SVGID_00000072257059765744298700000011011170644502566322_"
      id="use3" />
    </clipPath>
  2. Rasterize the file using EchoSVG.

Expected

The unused reference is ignored and rasterizing continues. This is the behaviour that Inkscape takes, which permits it to load the image:

e

Actual

Exception is thrown and the image is not rasterized.

io.sf.carte.echosvg.bridge.BridgeException: file:community.svg:-1
Cannot find the referenced element:
"#SVGID_00000072257059765744298700000011011170644502566322_"
specified on the element <use> - may be a problem of 'id'

The root cause is BridgeContext.java, line 752, where it is assumed incorrectly that all such Element instances have a valid Node reference:

Node ref = ur.getNode(uri, e);
if (ref == null) {
  throw new BridgeException(this, e, ERR_URI_BAD_TARGET, new Object[] { uri });

This exception is caught by SVGAbstractTransformer at line 261 and wrapped into a new exception:

throw new TranscoderException(ex);

By the time it is wrapped and re-thrown as a TranscoderException, it's too late to intervene. Perhaps instead of creating a BridgeException, there needs to be an UndefinedReferenceException subclass of BridgeException? That way the exception can still be caught by SVGAbstractTransformer yet passed along to the ErrorHandler instead of being wrapped and re-thrown?

Another idea would be to create an "Empty" node/element to represent a missing reference, but that would needlessly clutter the DOM or have any number of unintended side-effects, I imagine, because getReferencedNode is used in many places.

carlosame added a commit that referenced this issue Jun 14, 2023
Instead of throwing an exception (and stop processing) on a missing reference, just
report the error via the user agent and keep processing. This is what a conformant
user agent is supposed to do.

There are other circumstances (like other I/O errors) where it would make sense to
behave in the same way, but this is deferred to future updates.

The `slideshow` and `extension` modules are also affected.
@carlosame
Copy link
Member

Filed a PR that closes this.

@carlosame carlosame self-assigned this Jun 14, 2023
@carlosame carlosame added the spec compliance Some behavior may not be spec-compliant label Jun 14, 2023
@carlosame carlosame added this to the 0.3.1 milestone Jun 14, 2023
carlosame added a commit that referenced this issue Jun 15, 2023
Instead of throwing an exception (and stop processing) on a missing reference, just
report the error via the user agent and keep processing. This is what a conformant
user agent is supposed to do.

There are other circumstances (like other I/O errors) where it would make sense to
behave in the same way, but this is deferred to future updates.

The `slideshow` and `extension` modules are also affected.
carlosame added a commit that referenced this issue Jun 15, 2023
Instead of throwing an exception (and stop processing) on a missing reference, just
report the error via the user agent and keep processing. This is what a conformant
user agent is supposed to do.

There are other circumstances (like other I/O errors) where it would make sense to
behave in the same way, but this is deferred to future updates.

The `slideshow` and `extension` modules are also affected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec compliance Some behavior may not be spec-compliant
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant