Project

General

Profile

Bug #1397

Crashes if CoCoAHelp.xml is missing

Added by John Abbott over 4 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Category:
bug
Target version:
Start date:
21 Jan 2020
Due date:
% Done:

100%

Estimated time:
Spent time:

Description

If I make a manual query when the file CoCoAHelp.xml is not found where expected, an UNCAUGHT CoCoA ERROR happens, and the interpreter exits (crashes).

It would be better if it did not exit.


Related issues

Related to CoCoA-5 - Design #1631: Use filesystem::path instead of string (packageDir, CoCoAManFileName)New2021-11-12

Related to CoCoA-5 - Design #1504: OnlineHelp: XMLFileNameClosed2020-10-08

History

#1 Updated by Anna Maria Bigatti over 4 years ago

ouch!
it should never happen, really.
But it is bad. I'll fixi it.

#2 Updated by Anna Maria Bigatti over 4 years ago

I see that this give error with no crash (loading extra manuals). This was what worried me most.

ReloadMan(["aksjf"]);

#3 Updated by Anna Maria Bigatti over 4 years ago

  • Status changed from New to In Progress
  • Assignee set to Anna Maria Bigatti
  • % Done changed from 0 to 20

The problem is in the constructor (I think)

  index::index()
  {
    std::ostringstream os; // does not print
    myLoad(os);
  }

If myLoad fails, then UniqueIndex does not exist.
I guess this has to be fixed separating creation and initialization, but this is a very pervasive change.

hmmm, not today :-(

#4 Updated by John Abbott about 4 years ago

  • Target version changed from CoCoA-5.3.0 to CoCoA-5.4.0

#5 Updated by John Abbott over 2 years ago

If CoCoAHelp.xml is missing then the installation is broken (or there is a wrong path).
Crashing/aborting may be a reasonable action in these circumstances (who know what else is broken).
There should nevertheless be a helpful message printed on std::cerr before crashing.

#6 Updated by John Abbott over 2 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 20 to 80

I have just tried, and CoCoA-5 no longer crashes. It also produced a fairly reasonable error message.
Maybe the error message could be improved (made more comprehensible to non-expert users).

#7 Updated by John Abbott over 2 years ago

I have modified the error message slightly. Now it gives:

/**/ ?abc
--> ERROR: CoCoA-5 manual missing (or not readable); it should be in /home/jabbott/Work/CoCoALib-0.99/src/CoCoA-5/packages/../CoCoAManual/CoCoAHelp.xml
--> [CoCoALib] OnlineHelp::OpenXMLManual()
--> ?abc
--> ^^^^

I think this may be more comprehensible. Anna, what do you think?

#8 Updated by John Abbott over 2 years ago

It would be nice (& cleaner) if we could get rid of packages/../.
I think this should be possible.

#9 Updated by John Abbott over 2 years ago

There is a stackoverflow thread about getting dirname: https://stackoverflow.com/questions/3071665/getting-a-directory-name-from-a-filename

Apparently in C++17 one do something like the following:

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
    for(fs::path p : {"/var/tmp/example.txt", "/", "/var/tmp/."})
        std::cout << "The parent path of " << p
                  << " is " << p.parent_path() << '\n';
}

Of course, we're using C++14. But BOOST offers something similar...
According to the same stackoverflow thread, with BOOST one can do the following:
boost::filesystem::path p("C:\\folder\\foo.txt");
boost::filesystem::path dir = p.parent_path();

#10 Updated by John Abbott over 2 years ago

We probably need to change the fn CoCoAManFileName (around line 950 in OnlineHelp.C).
The return type should be a "path" (initially boost::filesystem::path)

const boost::filesystem::path& CoCoAManFileName()
{
  static const boost::filesystem::path UniqueCopy(boost::filesystem::path(packageDir).parent_path() / "CoCoAManual/CoCoAHelp.xml");
  return UniqueCopy;
}

NOTE should we also change the (global) variable packageDir so that it has type boost::filesystem::path? Probably!

#11 Updated by John Abbott over 2 years ago

  • Related to Design #1631: Use filesystem::path instead of string (packageDir, CoCoAManFileName) added

#12 Updated by Anna Maria Bigatti over 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 80 to 100

No longer crashes. So that's good.
Now we just need to clean up the path, but that's in a new issue #1631

#13 Updated by Anna Maria Bigatti about 2 years ago

Also available in: Atom PDF