/*
 * $Id: SourceOpSVGImpl.java 3665 2008-05-26 21:02:09Z uckelman $
 *
 * Copyright (c) 2008 by Joel Uckelman
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License (LGPL) as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, copies are available
 * at http://www.opensource.org.
 */

package VASSAL.tools.imageop;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import VASSAL.i18n.Resources;
import VASSAL.tools.ErrorDialog;
import VASSAL.tools.ReadErrorDialog;

/**
 * @author Joel Uckelman
 * @since 3.1.0
 */
public class OpErrorDialog {
  private OpErrorDialog() {}

  public static void error(ExecutionException e, ImageOp op) {
    // unpack the exception
    for (Throwable c = e; c != null; c = c.getCause()) {
      if (c instanceof IOException) {
        for (ImageOp src = op; src != null; src = src.getSource()) {
          if (src instanceof SourceOp) {
            // we had a file read error
            ReadErrorDialog.error(e, (IOException) c,
                                  ((SourceOp) src).getName());
            return;
          }
        }

        // otherwise we had some other kind of I/O problem
        ErrorDialog.error(
          Resources.getString("Error.io_error"),
          Resources.getString("Error.io_error"),
          e,
          Resources.getString("IOErrorDialog.io_error"),
          c.getMessage()
        );

        return;
      }
    }

    // otherwise this is a bug
    ErrorDialog.bug(e);
  }
}

@@ -902,16 +902,48 @@
 Dialog;%0A
+import VASSAL.tools.ErrorUtils;%0A
 import V
@@ -1180,94 +1180,103 @@
    f
-or (Throwable c = e; c != null; c = c.getCause()) %7B%0A      if (c instanceof IOException
+inal IOException ioe = ErrorUtils.getAncestorOfClass(IOException.class, e);%0A    if (ioe != null
 ) %7B%0A
@@ -1281,18 +1281,16 @@
 %7B%0A      
- 
- 
 for (Ima
@@ -1350,18 +1350,16 @@
         
-  
 if (src 
@@ -1391,18 +1391,16 @@
         
- 
- 
 // we ha
@@ -1419,18 +1419,16 @@
 d error%0A
-  
         
@@ -1458,58 +1458,12 @@
 (e, 
-(IOException) c,%0A                                 
+ioe,
  ((S
@@ -1494,34 +1494,32 @@
 ;%0A          
-  
 return;%0A
           %7D%0A
@@ -1502,26 +1502,24 @@
     return;%0A
-  
         %7D%0A  
@@ -1522,23 +1522,19 @@
 %7D%0A      
-  
 %7D%0A%0A
-  
       //
@@ -1582,18 +1582,16 @@
 problem%0A
-  
       Er
@@ -1607,34 +1607,32 @@
 .error(%0A        
-  
 Resources.getStr
@@ -1646,34 +1646,32 @@
 ror.io_error%22),%0A
-  
         Resource
@@ -1709,18 +1709,16 @@
         
-  
 e,%0A     
@@ -1716,26 +1716,24 @@
  e,%0A        
- 
- 
 Resources.ge
@@ -1779,11 +1779,11 @@
     
-  c
+ioe
 .get
@@ -1798,18 +1798,16 @@
 )%0A      
-  
 );%0A%0A    
@@ -1804,34 +1804,32 @@
   );%0A%0A      
- 
- 
 return;%0A
       %7D%0A    
@@ -1816,24 +1816,16 @@
 return;%0A
-      %7D%0A
     %7D%0A%0A 

Use ErrorUtils to drill through causal history.