command line: better error messages about config problems
Using a config name which refers to a context now triggers a specific error. The operation that cannot be continued is named explicitly: $ ./syncevolution @default [INFO] Configuration "@default" does not refer to a sync peer. [ERROR] Cannot proceed with sync without a configuration. The error message about missing configuration also became better: $ ./syncevolution foo@default [INFO] Configuration "foo@default" does not exist. [ERROR] Cannot proceed with sync without a configuration.
This commit is contained in:
parent
4c8cf8fa9f
commit
2614666ca2
|
@ -3454,11 +3454,40 @@ protected:
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("GNOME"), keyring.get());
|
||||
}
|
||||
|
||||
// Broken command line: treated like a sync, but config doesn't exist.
|
||||
{
|
||||
TestCmdline cmdline("keyring=KDE", "@foobar", NULL);
|
||||
cmdline.doit(false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"@foobar\" does not refer to a sync peer.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
|
||||
}
|
||||
{
|
||||
TestCmdline cmdline("keyring=KDE", "nosuchpeer@foobar", NULL);
|
||||
cmdline.doit(false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"nosuchpeer@foobar\" does not exist.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
|
||||
}
|
||||
|
||||
// empty config prop
|
||||
{
|
||||
TestCmdline cmdline("--configure", "@default", NULL);
|
||||
cmdline.doit();
|
||||
}
|
||||
|
||||
// Try broken command line again.
|
||||
{
|
||||
TestCmdline cmdline("keyring=KDE", "@foobar", NULL);
|
||||
cmdline.doit(false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"@foobar\" does not refer to a sync peer.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
|
||||
}
|
||||
{
|
||||
TestCmdline cmdline("keyring=KDE", "nosuchpeer@foobar", NULL);
|
||||
cmdline.doit(false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"nosuchpeer@foobar\" does not exist.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
|
||||
}
|
||||
|
||||
{
|
||||
TestCmdline cmdline("@foobar", NULL);
|
||||
boost::shared_ptr<SyncContext> context = cmdline.parse();
|
||||
|
@ -3472,9 +3501,6 @@ protected:
|
|||
{
|
||||
TestCmdline cmdline("--keyring", "--configure", "@default", NULL);
|
||||
cmdline.doit();
|
||||
}
|
||||
{
|
||||
TestCmdline cmdline("@foobar", NULL);
|
||||
boost::shared_ptr<SyncContext> context = cmdline.parse();
|
||||
CPPUNIT_ASSERT(context);
|
||||
InitStateTri keyring = context->getKeyring();
|
||||
|
@ -3484,9 +3510,6 @@ protected:
|
|||
{
|
||||
TestCmdline cmdline("--keyring=KDE", "--configure", "@default", NULL);
|
||||
cmdline.doit();
|
||||
}
|
||||
{
|
||||
TestCmdline cmdline("@foobar", NULL);
|
||||
boost::shared_ptr<SyncContext> context = cmdline.parse();
|
||||
CPPUNIT_ASSERT(context);
|
||||
InitStateTri keyring = context->getKeyring();
|
||||
|
@ -3495,12 +3518,34 @@ protected:
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("KDE"), keyring.get());
|
||||
}
|
||||
|
||||
// create by setting keyring in @default, then update;
|
||||
// @default not strictly needed
|
||||
rm_r(m_testDir);
|
||||
{
|
||||
TestCmdline cmdline("keyring=KDE", "--configure", "@default", NULL);
|
||||
cmdline.doit();
|
||||
boost::shared_ptr<SyncContext> context = cmdline.parse();
|
||||
CPPUNIT_ASSERT(context);
|
||||
InitStateTri keyring = context->getKeyring();
|
||||
CPPUNIT_ASSERT_EQUAL(true, keyring.wasSet());
|
||||
CPPUNIT_ASSERT_EQUAL(InitStateTri::VALUE_STRING, keyring.getValue());
|
||||
}
|
||||
{
|
||||
TestCmdline cmdline("keyring=yes", "--configure", "@default", NULL);
|
||||
cmdline.doit();
|
||||
boost::shared_ptr<SyncContext> context = cmdline.parse();
|
||||
CPPUNIT_ASSERT(context);
|
||||
InitStateTri keyring = context->getKeyring();
|
||||
CPPUNIT_ASSERT_EQUAL(true, keyring.wasSet());
|
||||
CPPUNIT_ASSERT_EQUAL(InitStateTri::VALUE_TRUE, keyring.getValue());
|
||||
}
|
||||
|
||||
// allow sync operation although --keyring was set
|
||||
{
|
||||
TestCmdline cmdline("keyring=GNOME", "foobar@default", NULL);
|
||||
cmdline.doit(false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[ERROR] No configuration for server \"foobar@default\" found.\n[ERROR] cannot proceed without configuration"), cmdline.m_err.str());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"foobar@default\" does not exist.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
|
||||
}
|
||||
|
||||
// catch invalid "keyring" value
|
||||
|
|
|
@ -2872,12 +2872,18 @@ void SyncContext::setStableRelease(bool isStableRelease)
|
|||
IsStableRelease = isStableRelease;
|
||||
}
|
||||
|
||||
void SyncContext::checkConfig() const
|
||||
void SyncContext::checkConfig(const std::string &operation) const
|
||||
{
|
||||
std::string peer, context;
|
||||
splitConfigString(m_server, peer, context);
|
||||
if (isConfigNeeded() &&
|
||||
!exists()) {
|
||||
SE_LOG_ERROR(NULL, NULL, "No configuration for server \"%s\" found.", m_server.c_str());
|
||||
throwError("cannot proceed without configuration");
|
||||
(!exists() || peer.empty())) {
|
||||
if (peer.empty()) {
|
||||
SE_LOG_INFO(NULL, NULL, "Configuration \"%s\" does not refer to a sync peer.", m_server.c_str());
|
||||
} else {
|
||||
SE_LOG_INFO(NULL, NULL, "Configuration \"%s\" does not exist.", m_server.c_str());
|
||||
}
|
||||
throwError(StringPrintf("Cannot proceed with %s without a configuration.", operation.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2885,7 +2891,7 @@ SyncMLStatus SyncContext::sync(SyncReport *report)
|
|||
{
|
||||
SyncMLStatus status = STATUS_OK;
|
||||
|
||||
checkConfig();
|
||||
checkConfig("sync");
|
||||
|
||||
// redirect logging as soon as possible
|
||||
SourceList sourceList(*this, m_doLogging);
|
||||
|
@ -3895,7 +3901,7 @@ SyncMLStatus SyncContext::handleException()
|
|||
|
||||
void SyncContext::status()
|
||||
{
|
||||
checkConfig();
|
||||
checkConfig("status check");
|
||||
|
||||
SourceList sourceList(*this, false);
|
||||
initSources(sourceList);
|
||||
|
@ -3947,7 +3953,7 @@ void SyncContext::status()
|
|||
|
||||
void SyncContext::checkStatus(SyncReport &report)
|
||||
{
|
||||
checkConfig();
|
||||
checkConfig("status check");
|
||||
|
||||
SourceList sourceList(*this, false);
|
||||
initSources(sourceList);
|
||||
|
@ -4037,7 +4043,7 @@ bool SyncContext::checkForScriptAbort(SharedSession session)
|
|||
|
||||
void SyncContext::restore(const string &dirname, RestoreDatabase database)
|
||||
{
|
||||
checkConfig();
|
||||
checkConfig("restore");
|
||||
|
||||
SourceList sourceList(*this, false);
|
||||
sourceList.accessSession(dirname.c_str());
|
||||
|
|
|
@ -237,8 +237,10 @@ class SyncContext : public SyncConfig {
|
|||
|
||||
/**
|
||||
* throws error if config is needed and not available
|
||||
*
|
||||
* @param operation a noun describing what is to be done next ("proceed with %s", operation)
|
||||
*/
|
||||
void checkConfig() const;
|
||||
void checkConfig(const std::string &operation) const;
|
||||
|
||||
/**
|
||||
* Sets configuration filters. Currently only used in local sync
|
||||
|
|
Loading…
Reference in a new issue